OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/guest_view/app_view/app_view_guest.h" | 5 #include "extensions/browser/guest_view/app_view/app_view_guest.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | |
9 #include "chrome/browser/extensions/extension_service.h" | |
10 #include "chrome/browser/guest_view/app_view/app_view_constants.h" | |
11 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | |
12 #include "chrome/common/chrome_switches.h" | |
13 #include "components/renderer_context_menu/context_menu_delegate.h" | |
14 #include "content/public/browser/render_view_host.h" | 8 #include "content/public/browser/render_view_host.h" |
15 #include "content/public/common/renderer_preferences.h" | 9 #include "content/public/common/renderer_preferences.h" |
16 #include "extensions/browser/api/app_runtime/app_runtime_api.h" | 10 #include "extensions/browser/api/app_runtime/app_runtime_api.h" |
11 #include "extensions/browser/api/extensions_api_client.h" | |
17 #include "extensions/browser/event_router.h" | 12 #include "extensions/browser/event_router.h" |
18 #include "extensions/browser/extension_host.h" | 13 #include "extensions/browser/extension_host.h" |
14 #include "extensions/browser/extension_registry.h" | |
19 #include "extensions/browser/extension_system.h" | 15 #include "extensions/browser/extension_system.h" |
16 #include "extensions/browser/guest_view/app_view/app_view_constants.h" | |
20 #include "extensions/browser/guest_view/guest_view_manager.h" | 17 #include "extensions/browser/guest_view/guest_view_manager.h" |
21 #include "extensions/browser/lazy_background_task_queue.h" | 18 #include "extensions/browser/lazy_background_task_queue.h" |
19 #include "extensions/browser/process_manager.h" | |
22 #include "extensions/browser/view_type_utils.h" | 20 #include "extensions/browser/view_type_utils.h" |
23 #include "extensions/common/api/app_runtime.h" | 21 #include "extensions/common/api/app_runtime.h" |
24 #include "extensions/common/extension_messages.h" | 22 #include "extensions/common/extension_messages.h" |
23 #include "extensions/common/switches.h" | |
25 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
26 | 25 |
27 namespace app_runtime = extensions::core_api::app_runtime; | 26 namespace app_runtime = extensions::core_api::app_runtime; |
28 | 27 |
29 using content::RenderFrameHost; | 28 using content::RenderFrameHost; |
30 using content::WebContents; | 29 using content::WebContents; |
31 using extensions::ExtensionHost; | 30 using extensions::ExtensionHost; |
32 | 31 |
33 namespace extensions { | 32 namespace extensions { |
34 | 33 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 response_info->callback); | 85 response_info->callback); |
87 | 86 |
88 response_map->erase(guest_instance_id); | 87 response_map->erase(guest_instance_id); |
89 return true; | 88 return true; |
90 } | 89 } |
91 | 90 |
92 // static | 91 // static |
93 GuestViewBase* AppViewGuest::Create(content::BrowserContext* browser_context, | 92 GuestViewBase* AppViewGuest::Create(content::BrowserContext* browser_context, |
94 int guest_instance_id) { | 93 int guest_instance_id) { |
95 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 94 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
96 switches::kEnableAppView)) { | 95 extensions::switches::kEnableAppView)) { |
97 return NULL; | 96 return NULL; |
98 } | 97 } |
99 return new AppViewGuest(browser_context, guest_instance_id); | 98 return new AppViewGuest(browser_context, guest_instance_id); |
100 } | 99 } |
101 | 100 |
102 AppViewGuest::AppViewGuest(content::BrowserContext* browser_context, | 101 AppViewGuest::AppViewGuest(content::BrowserContext* browser_context, |
103 int guest_instance_id) | 102 int guest_instance_id) |
104 : GuestView<AppViewGuest>(browser_context, guest_instance_id), | 103 : GuestView<AppViewGuest>(browser_context, guest_instance_id), |
104 app_view_guest_delegate_( | |
105 ExtensionsAPIClient::Get()->CreateAppViewGuestDelegate()), | |
105 weak_ptr_factory_(this) { | 106 weak_ptr_factory_(this) { |
106 } | 107 } |
107 | 108 |
108 AppViewGuest::~AppViewGuest() { | 109 AppViewGuest::~AppViewGuest() { |
109 } | 110 } |
110 | 111 |
111 WindowController* AppViewGuest::GetExtensionWindowController() const { | 112 WindowController* AppViewGuest::GetExtensionWindowController() const { |
112 return NULL; | 113 return NULL; |
113 } | 114 } |
114 | 115 |
115 content::WebContents* AppViewGuest::GetAssociatedWebContents() const { | 116 content::WebContents* AppViewGuest::GetAssociatedWebContents() const { |
116 return guest_web_contents(); | 117 return guest_web_contents(); |
117 } | 118 } |
118 | 119 |
119 bool AppViewGuest::OnMessageReceived(const IPC::Message& message) { | 120 bool AppViewGuest::OnMessageReceived(const IPC::Message& message) { |
120 bool handled = true; | 121 bool handled = true; |
121 IPC_BEGIN_MESSAGE_MAP(AppViewGuest, message) | 122 IPC_BEGIN_MESSAGE_MAP(AppViewGuest, message) |
122 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 123 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
123 IPC_MESSAGE_UNHANDLED(handled = false) | 124 IPC_MESSAGE_UNHANDLED(handled = false) |
124 IPC_END_MESSAGE_MAP() | 125 IPC_END_MESSAGE_MAP() |
125 return handled; | 126 return handled; |
126 } | 127 } |
127 | 128 |
128 bool AppViewGuest::HandleContextMenu(const content::ContextMenuParams& params) { | 129 bool AppViewGuest::HandleContextMenu(const content::ContextMenuParams& params) { |
129 ContextMenuDelegate* menu_delegate = | 130 return app_view_guest_delegate_->OnHandleContextMenu(guest_web_contents(), |
Yoyo Zhou
2014/08/19 21:55:08
I agree that this is better called just HandleCont
| |
130 ContextMenuDelegate::FromWebContents(guest_web_contents()); | 131 params); |
131 DCHECK(menu_delegate); | |
132 | |
133 scoped_ptr<RenderViewContextMenu> menu = | |
134 menu_delegate->BuildMenu(guest_web_contents(), params); | |
135 menu_delegate->ShowMenu(menu.Pass()); | |
136 return true; | |
137 } | 132 } |
138 | 133 |
139 const char* AppViewGuest::GetAPINamespace() { | 134 const char* AppViewGuest::GetAPINamespace() { |
140 return appview::kEmbedderAPINamespace; | 135 return appview::kEmbedderAPINamespace; |
141 } | 136 } |
142 | 137 |
143 void AppViewGuest::CreateWebContents( | 138 void AppViewGuest::CreateWebContents( |
144 const std::string& embedder_extension_id, | 139 const std::string& embedder_extension_id, |
145 int embedder_render_process_id, | 140 int embedder_render_process_id, |
146 const base::DictionaryValue& create_params, | 141 const base::DictionaryValue& create_params, |
147 const WebContentsCreatedCallback& callback) { | 142 const WebContentsCreatedCallback& callback) { |
148 std::string app_id; | 143 std::string app_id; |
149 if (!create_params.GetString(appview::kAppID, &app_id)) { | 144 if (!create_params.GetString(appview::kAppID, &app_id)) { |
150 callback.Run(NULL); | 145 callback.Run(NULL); |
151 return; | 146 return; |
152 } | 147 } |
153 | 148 |
154 const base::DictionaryValue* data = NULL; | 149 const base::DictionaryValue* data = NULL; |
155 if (!create_params.GetDictionary(appview::kData, &data)) { | 150 if (!create_params.GetDictionary(appview::kData, &data)) { |
156 callback.Run(NULL); | 151 callback.Run(NULL); |
157 return; | 152 return; |
158 } | 153 } |
159 | 154 |
160 ExtensionService* service = | 155 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context()); |
161 ExtensionSystem::Get(browser_context())->extension_service(); | 156 const Extension* guest_extension = |
162 const Extension* guest_extension = service->GetExtensionById(app_id, false); | 157 registry->GetExtensionById(app_id, ExtensionRegistry::ENABLED); |
not at google - send to devlin
2014/08/19 20:19:02
Just registry->enabled_extensions()->GetByID(app_i
| |
163 const Extension* embedder_extension = | 158 const Extension* embedder_extension = registry->GetExtensionById( |
164 service->GetExtensionById(embedder_extension_id, false); | 159 embedder_extension_id, ExtensionRegistry::ENABLED); |
165 | 160 |
166 if (!guest_extension || !guest_extension->is_platform_app() || | 161 if (!guest_extension || !guest_extension->is_platform_app() || |
167 !embedder_extension | !embedder_extension->is_platform_app()) { | 162 !embedder_extension | !embedder_extension->is_platform_app()) { |
168 callback.Run(NULL); | 163 callback.Run(NULL); |
169 return; | 164 return; |
170 } | 165 } |
171 | 166 |
172 pending_response_map.Get().insert( | 167 pending_response_map.Get().insert( |
173 std::make_pair(GetGuestInstanceID(), | 168 std::make_pair(GetGuestInstanceID(), |
174 make_linked_ptr(new ResponseInfo( | 169 make_linked_ptr(new ResponseInfo( |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 | 245 |
251 scoped_ptr<base::DictionaryValue> embed_request(new base::DictionaryValue()); | 246 scoped_ptr<base::DictionaryValue> embed_request(new base::DictionaryValue()); |
252 embed_request->SetInteger(appview::kGuestInstanceID, GetGuestInstanceID()); | 247 embed_request->SetInteger(appview::kGuestInstanceID, GetGuestInstanceID()); |
253 embed_request->SetString(appview::kEmbedderID, embedder_extension_id()); | 248 embed_request->SetString(appview::kEmbedderID, embedder_extension_id()); |
254 embed_request->Set(appview::kData, data.release()); | 249 embed_request->Set(appview::kData, data.release()); |
255 AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( | 250 AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( |
256 browser_context(), embed_request.Pass(), extension_host->extension()); | 251 browser_context(), embed_request.Pass(), extension_host->extension()); |
257 } | 252 } |
258 | 253 |
259 } // namespace extensions | 254 } // namespace extensions |
OLD | NEW |