Skip to content

Commit 07dc32d

Browse files
committed
Menu and Shell API ported
1 parent 094674d commit 07dc32d

39 files changed

+1440
-103
lines changed

nw.gypi

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,21 +636,45 @@
636636
'nw_base',
637637
'<(DEPTH)/content/nw/src/api/api.gyp:nw_api',
638638
'<(DEPTH)/content/nw/src/api/api_registration.gyp:nw_api_registration',
639+
'<(DEPTH)/extensions/browser/api/api_registration.gyp:extensions_api_registration',
639640
],
640641
'include_dirs': [
641642
'<(DEPTH)/third_party/mojo/src',
642643
'<(SHARED_INTERMEDIATE_DIR)/blink',
643644
'<(SHARED_INTERMEDIATE_DIR)/blink/bindings/core/v8/',
644645
],
645646
'defines!': ['CONTENT_IMPLEMENTATION'],
646-
'msvs_disabled_warnings': [ 4267, 4800 ],
647+
'msvs_disabled_warnings': [ 4267, 4800, 4189 ],
647648
'sources': [
648649
'src/api/nw_app_api.cc',
649650
'src/api/nw_app_api.h',
650651
'src/api/nw_clipboard_api.cc',
651652
'src/api/nw_clipboard_api.h',
652653
'src/api/nw_window_api.cc',
653654
'src/api/nw_window_api.h',
655+
'src/api/nw_menu_api.cc',
656+
'src/api/nw_menu_api.h',
657+
'src/api/nw_object_api.cc',
658+
'src/api/nw_object_api.h',
659+
'src/api/nw_shell_api.cc',
660+
'src/api/nw_shell_api.h',
661+
'src/api/object_manager.cc',
662+
'src/api/object_manager.h',
663+
'src/api/object_manager_factory.cc',
664+
'src/api/object_manager_factory.h',
665+
'src/api/base/base.cc',
666+
'src/api/base/base.h',
667+
'src/api/menu/menu.cc',
668+
'src/api/menu/menu.h',
669+
'src/api/menu/menu_delegate.cc',
670+
'src/api/menu/menu_delegate.h',
671+
'src/api/menu/menu_views.cc',
672+
'src/api/menu/menu_views.h',
673+
'src/api/menuitem/menuitem.cc',
674+
'src/api/menuitem/menuitem.h',
675+
'src/api/menuitem/menuitem_views.cc',
676+
'src/api/shell/shell.cc',
677+
'src/api/shell/shell.h',
654678
'src/nw_content.cc',
655679
'src/nw_content.h',
656680
'src/nw_custom_bindings.cc',

src/api/_api_features.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919
"channel": "stable",
2020
"contexts": ["blessed_extension"]
2121
},
22+
"nw.Menu": {
23+
"channel": "stable",
24+
"contexts": ["blessed_extension"]
25+
},
26+
"nw.Shell": {
27+
"channel": "stable",
28+
"contexts": ["blessed_extension"]
29+
},
30+
"nw.Object": {
31+
"channel": "stable",
32+
"contexts": ["blessed_extension"]
33+
},
2234
"nw.test": {
2335
"channel": "stable",
2436
"contexts": ["blessed_extension"]

src/api/api.gyp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33
{
44
'target_name': 'nw_api',
55
'type': 'static_library',
6+
'sources': [
7+
'<@(schema_files)',
8+
],
9+
# TODO(jschuh): http://crbug.com/167187 size_t -> int
10+
'msvs_disabled_warnings': [ 4267 ],
611
'includes': [
712
'../../../../build/json_schema_bundle_compile.gypi',
813
'../../../../build/json_schema_compile.gypi',
914
'schemas.gypi',
1015
],
16+
'dependencies': [
17+
'<@(schema_dependencies)',
18+
],
1119
},
1220
]
1321
}

src/api/base/base.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
#include "base/logging.h"
2424
#include "base/values.h"
2525

26-
namespace nwapi {
26+
namespace nw {
2727

2828
Base::Base(int id,
29-
const base::WeakPtr<DispatcherHost>& dispatcher_host,
30-
const base::DictionaryValue& option)
29+
const base::WeakPtr<ObjectManager>& object_manager,
30+
const base::DictionaryValue& option,
31+
const std::string& extension_id)
3132
: id_(id),
32-
dispatcher_host_(dispatcher_host) {
33+
extension_id_(extension_id),
34+
object_manager_(object_manager) {
3335
}
3436

3537
Base::~Base() {
@@ -50,4 +52,4 @@ void Base::CallSync(const std::string& method,
5052
<< " arguments:" << arguments;
5153
}
5254

53-
} // namespace nwapi
55+
} // namespace nw

src/api/base/base.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ class DictionaryValue;
3131
class ListValue;
3232
}
3333

34-
namespace nwapi {
34+
namespace nw {
3535

36-
class DispatcherHost;
36+
class ObjectManager;
3737

3838
class Base {
3939
public:
4040
Base(int id,
41-
const base::WeakPtr<DispatcherHost>& dispatcher_host,
42-
const base::DictionaryValue& option);
41+
const base::WeakPtr<ObjectManager>& manager,
42+
const base::DictionaryValue& option,
43+
const std::string& extension_id);
4344
virtual ~Base();
4445

4546
virtual void Call(const std::string& method,
@@ -49,11 +50,12 @@ class Base {
4950
base::ListValue* result);
5051

5152
int id() const { return id_; }
52-
DispatcherHost* dispatcher_host() const { return dispatcher_host_.get(); }
53+
std::string extension_id_;
54+
ObjectManager* object_manager() const { return object_manager_.get(); }
5355

5456
private:
5557
int id_;
56-
base::WeakPtr<DispatcherHost> dispatcher_host_;
58+
base::WeakPtr<ObjectManager> object_manager_;
5759

5860
DISALLOW_COPY_AND_ASSIGN(Base);
5961
};

src/api/menu/menu.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
#include "content/nw/src/api/menu/menu.h"
2222

2323
#include "base/values.h"
24-
#include "content/nw/src/api/dispatcher_host.h"
24+
#include "content/nw/src/api/object_manager.h"
2525
#include "content/nw/src/api/menuitem/menuitem.h"
26-
#include "content/nw/src/nw_shell.h"
2726

28-
namespace nwapi {
27+
namespace nw {
2928

3029
Menu::Menu(int id,
31-
const base::WeakPtr<DispatcherHost>& dispatcher_host,
32-
const base::DictionaryValue& option)
33-
: Base(id, dispatcher_host, option), enable_show_event_(false) {
30+
const base::WeakPtr<ObjectManager>& object_manager,
31+
const base::DictionaryValue& option,
32+
const std::string& extension_id)
33+
: Base(id, object_manager, option, extension_id), enable_show_event_(false) {
3434
Create(option);
3535
}
3636

@@ -43,26 +43,26 @@ void Menu::Call(const std::string& method,
4343
if (method == "Append") {
4444
int object_id = 0;
4545
arguments.GetInteger(0, &object_id);
46-
Append(dispatcher_host()->GetApiObject<MenuItem>(object_id));
46+
Append(object_manager()->GetApiObject<MenuItem>(object_id));
4747
} else if (method == "Insert") {
4848
int object_id = 0;
4949
arguments.GetInteger(0, &object_id);
5050
int pos = 0;
5151
arguments.GetInteger(1, &pos);
52-
Insert(dispatcher_host()->GetApiObject<MenuItem>(object_id), pos);
52+
Insert(object_manager()->GetApiObject<MenuItem>(object_id), pos);
5353
} else if (method == "Remove") {
5454
int object_id = 0;
5555
arguments.GetInteger(0, &object_id);
5656
int pos = 0;
5757
arguments.GetInteger(1, &pos);
58-
Remove(dispatcher_host()->GetApiObject<MenuItem>(object_id), pos);
58+
Remove(object_manager()->GetApiObject<MenuItem>(object_id), pos);
5959
} else if (method == "Popup") {
6060
int x = 0;
6161
arguments.GetInteger(0, &x);
6262
int y = 0;
6363
arguments.GetInteger(1, &y);
64-
Popup(x, y, content::Shell::FromRenderViewHost(
65-
dispatcher_host()->render_view_host()));
64+
// Popup(x, y, content::Shell::FromRenderViewHost(
65+
// object_manager()->render_view_host()));
6666
} else if (method == "EnableShowEvent") {
6767
arguments.GetBoolean(0, &enable_show_event_);
6868
} else {
@@ -71,4 +71,4 @@ void Menu::Call(const std::string& method,
7171
}
7272
}
7373

74-
} // namespace nwapi
74+
} // namespace nw

src/api/menu/menu.h

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ class NativeWindowCocoa;
4949
#include "content/nw/src/api/menu/menu_delegate.h"
5050
#include "chrome/browser/status_icons/status_icon_menu_model.h"
5151
#include "ui/views/focus/focus_manager.h"
52-
namespace nw {
53-
class NativeWindowAura;
52+
namespace extensions {
53+
class AppWindow;
5454
}
5555

56-
namespace nwapi {
56+
namespace nw {
5757
class Menu;
5858
}
5959

@@ -71,7 +71,7 @@ class NwMenuModel : public SimpleMenuModel {
7171
bool HasIcons() const override;
7272

7373
protected:
74-
friend class nwapi::Menu;
74+
friend class nw::Menu;
7575
};
7676

7777
} // namespace ui
@@ -82,15 +82,16 @@ namespace content {
8282
class Shell;
8383
}
8484

85-
namespace nwapi {
85+
namespace nw {
8686

8787
class MenuItem;
8888

8989
class Menu : public Base {
9090
public:
9191
Menu(int id,
92-
const base::WeakPtr<DispatcherHost>& dispatcher_host,
93-
const base::DictionaryValue& option);
92+
const base::WeakPtr<ObjectManager>& object_manager,
93+
const base::DictionaryValue& option,
94+
const std::string& extension_id);
9495
~Menu() override;
9596

9697
void Call(const std::string& method,
@@ -102,20 +103,15 @@ class Menu : public Base {
102103
#endif
103104

104105
bool enable_show_event() { return enable_show_event_; }
105-
protected:
106106
bool enable_show_event_;
107107

108-
private:
109-
friend class MenuItem;
110-
friend class Tray;
111-
112108
// Platform-independent implementations
113109
void Create(const base::DictionaryValue& option);
114110
void Destroy();
115111
void Append(MenuItem* menu_item);
116112
void Insert(MenuItem* menu_item, int pos);
117113
void Remove(MenuItem* menu_item, int pos);
118-
void Popup(int x, int y, content::Shell*);
114+
//void Popup(int x, int y, content::Shell*);
119115

120116
#if defined(OS_LINUX)
121117
std::vector<MenuItem*> menu_items;
@@ -140,17 +136,16 @@ class Menu : public Base {
140136
void UpdateStates();
141137

142138
#elif defined(OS_WIN)
143-
friend class nw::NativeWindowAura;
144139

145140
void Rebuild(const HMENU *parent_menu = NULL);
146141
void UpdateStates();
147-
void SetWindow(nw::NativeWindowAura* win);
142+
void SetWindow(extensions::AppWindow* win);
148143

149144
//**Never Try to free this pointer**
150145
//We get it from top widget
151146
views::FocusManager *focus_manager_;
152147
std::vector<MenuItem*> menu_items_;
153-
nw::NativeWindowAura* window_;
148+
extensions::AppWindow* window_;
154149
// Flag to indicate the menu has been modified since last show, so we should
155150
// rebuild the menu before next show.
156151
bool is_menu_modified_;
@@ -166,6 +161,6 @@ class Menu : public Base {
166161
DISALLOW_COPY_AND_ASSIGN(Menu);
167162
};
168163

169-
} // namespace nwapi
164+
} // namespace nw
170165

171166
#endif // CONTENT_NW_SRC_API_MENU_MENU_H_

src/api/menu/menu_delegate.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222

2323
#include "base/logging.h"
2424
#include "base/strings/string16.h"
25-
#include "content/nw/src/api/dispatcher_host.h"
25+
#include "content/nw/src/api/object_manager.h"
2626
#include "content/nw/src/api/menuitem/menuitem.h"
2727

28-
namespace nwapi {
28+
namespace nw {
2929

30-
MenuDelegate::MenuDelegate(DispatcherHost* dispatcher_host)
31-
: dispatcher_host_(dispatcher_host) {
30+
MenuDelegate::MenuDelegate(ObjectManager* object_manager)
31+
: object_manager_(object_manager) {
3232
}
3333

3434
MenuDelegate::~MenuDelegate() {
@@ -38,15 +38,15 @@ bool MenuDelegate::IsCommandIdChecked(int command_id) const {
3838
if (command_id < 0)
3939
return false;
4040

41-
MenuItem* item = dispatcher_host_->GetApiObject<MenuItem>(command_id);
41+
MenuItem* item = object_manager_->GetApiObject<MenuItem>(command_id);
4242
return item->is_checked_;
4343
}
4444

4545
bool MenuDelegate::IsCommandIdEnabled(int command_id) const {
4646
if (command_id < 0)
4747
return false;
4848

49-
MenuItem* item = dispatcher_host_->GetApiObject<MenuItem>(command_id);
49+
MenuItem* item = object_manager_->GetApiObject<MenuItem>(command_id);
5050
if (!item)
5151
return false;
5252
return item->is_enabled_;
@@ -56,14 +56,14 @@ bool MenuDelegate::IsItemForCommandIdDynamic(int command_id) const {
5656
if (command_id < 0)
5757
return false;
5858

59-
MenuItem* item = dispatcher_host_->GetApiObject<MenuItem>(command_id);
59+
MenuItem* item = object_manager_->GetApiObject<MenuItem>(command_id);
6060
if (!item)
6161
return false;
6262
return item->is_modified_;
6363
}
6464

6565
base::string16 MenuDelegate::GetLabelForCommandId(int command_id) const {
66-
MenuItem* item = dispatcher_host_->GetApiObject<MenuItem>(command_id);
66+
MenuItem* item = object_manager_->GetApiObject<MenuItem>(command_id);
6767
return item->label_;
6868
}
6969

@@ -76,7 +76,7 @@ bool MenuDelegate::GetAcceleratorForCommandId(
7676

7777
bool MenuDelegate::GetIconForCommandId(int command_id,
7878
gfx::Image* icon) const {
79-
MenuItem* item = dispatcher_host_->GetApiObject<MenuItem>(command_id);
79+
MenuItem* item = object_manager_->GetApiObject<MenuItem>(command_id);
8080
if (!item)
8181
return false;
8282
if (item->icon_.IsEmpty())
@@ -90,7 +90,7 @@ void MenuDelegate::ExecuteCommand(int command_id, int event_flags) {
9090
if (command_id < 0)
9191
return;
9292

93-
MenuItem* item = dispatcher_host_->GetApiObject<MenuItem>(command_id);
93+
MenuItem* item = object_manager_->GetApiObject<MenuItem>(command_id);
9494
if (!item)
9595
return;
9696
item->OnClick();
@@ -100,7 +100,7 @@ bool MenuDelegate::HasIcon(int command_id) {
100100
if (command_id < 0)
101101
return false;
102102

103-
MenuItem* item = dispatcher_host_->GetApiObject<MenuItem>(command_id);
103+
MenuItem* item = object_manager_->GetApiObject<MenuItem>(command_id);
104104
if (!item)
105105
return false;
106106
return !item->icon_.IsEmpty();

0 commit comments

Comments
 (0)