Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: extensions/browser/guest_view/app_view/app_view_guest.cc

Issue 486903002: Moving app_view to extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
19 #include "extensions/browser/extension_system.h" 14 #include "extensions/browser/extension_system.h"
15 #include "extensions/browser/guest_view/app_view/app_view_constants.h"
20 #include "extensions/browser/guest_view/guest_view_manager.h" 16 #include "extensions/browser/guest_view/guest_view_manager.h"
21 #include "extensions/browser/lazy_background_task_queue.h" 17 #include "extensions/browser/lazy_background_task_queue.h"
18 #include "extensions/browser/process_manager.h"
22 #include "extensions/browser/view_type_utils.h" 19 #include "extensions/browser/view_type_utils.h"
23 #include "extensions/common/api/app_runtime.h" 20 #include "extensions/common/api/app_runtime.h"
24 #include "extensions/common/extension_messages.h" 21 #include "extensions/common/extension_messages.h"
22 #include "extensions/common/switches.h"
25 #include "ipc/ipc_message_macros.h" 23 #include "ipc/ipc_message_macros.h"
26 24
27 namespace app_runtime = extensions::core_api::app_runtime; 25 namespace app_runtime = extensions::core_api::app_runtime;
28 26
29 using content::RenderFrameHost; 27 using content::RenderFrameHost;
30 using content::WebContents; 28 using content::WebContents;
31 using extensions::ExtensionHost; 29 using extensions::ExtensionHost;
32 30
33 namespace extensions { 31 namespace extensions {
34 32
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 response_info->callback); 84 response_info->callback);
87 85
88 response_map->erase(guest_instance_id); 86 response_map->erase(guest_instance_id);
89 return true; 87 return true;
90 } 88 }
91 89
92 // static 90 // static
93 GuestViewBase* AppViewGuest::Create(content::BrowserContext* browser_context, 91 GuestViewBase* AppViewGuest::Create(content::BrowserContext* browser_context,
94 int guest_instance_id) { 92 int guest_instance_id) {
95 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 93 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
96 switches::kEnableAppView)) { 94 extensions::switches::kEnableAppView)) {
97 return NULL; 95 return NULL;
98 } 96 }
99 return new AppViewGuest(browser_context, guest_instance_id); 97 return new AppViewGuest(
98 ExtensionsAPIClient::Get()->CreateAppViewGuestDelegate(),
99 browser_context,
100 guest_instance_id);
100 } 101 }
101 102
102 AppViewGuest::AppViewGuest(content::BrowserContext* browser_context, 103 AppViewGuest::AppViewGuest(AppViewGuestDelegate* app_view_guest_delegate,
Xi Han 2014/08/18 21:29:11 The AppViewGuestDelegate doesn't need to be expose
104 content::BrowserContext* browser_context,
103 int guest_instance_id) 105 int guest_instance_id)
104 : GuestView<AppViewGuest>(browser_context, guest_instance_id), 106 : GuestView<AppViewGuest>(browser_context, guest_instance_id),
107 app_view_guest_delegate_(app_view_guest_delegate),
105 weak_ptr_factory_(this) { 108 weak_ptr_factory_(this) {
106 } 109 }
107 110
108 AppViewGuest::~AppViewGuest() { 111 AppViewGuest::~AppViewGuest() {
109 } 112 }
110 113
111 WindowController* AppViewGuest::GetExtensionWindowController() const { 114 WindowController* AppViewGuest::GetExtensionWindowController() const {
112 return NULL; 115 return NULL;
113 } 116 }
114 117
115 content::WebContents* AppViewGuest::GetAssociatedWebContents() const { 118 content::WebContents* AppViewGuest::GetAssociatedWebContents() const {
116 return guest_web_contents(); 119 return guest_web_contents();
117 } 120 }
118 121
119 bool AppViewGuest::OnMessageReceived(const IPC::Message& message) { 122 bool AppViewGuest::OnMessageReceived(const IPC::Message& message) {
120 bool handled = true; 123 bool handled = true;
121 IPC_BEGIN_MESSAGE_MAP(AppViewGuest, message) 124 IPC_BEGIN_MESSAGE_MAP(AppViewGuest, message)
122 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) 125 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
123 IPC_MESSAGE_UNHANDLED(handled = false) 126 IPC_MESSAGE_UNHANDLED(handled = false)
124 IPC_END_MESSAGE_MAP() 127 IPC_END_MESSAGE_MAP()
125 return handled; 128 return handled;
126 } 129 }
127 130
128 bool AppViewGuest::HandleContextMenu(const content::ContextMenuParams& params) { 131 bool AppViewGuest::HandleContextMenu(const content::ContextMenuParams& params) {
129 ContextMenuDelegate* menu_delegate = 132 return app_view_guest_delegate_->HandleContextMenu(guest_web_contents(),
130 ContextMenuDelegate::FromWebContents(guest_web_contents()); 133 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 } 134 }
138 135
139 const char* AppViewGuest::GetAPINamespace() { 136 const char* AppViewGuest::GetAPINamespace() {
140 return appview::kEmbedderAPINamespace; 137 return appview::kEmbedderAPINamespace;
141 } 138 }
142 139
143 void AppViewGuest::CreateWebContents( 140 void AppViewGuest::CreateWebContents(
144 const std::string& embedder_extension_id, 141 const std::string& embedder_extension_id,
145 int embedder_render_process_id, 142 int embedder_render_process_id,
146 const base::DictionaryValue& create_params, 143 const base::DictionaryValue& create_params,
147 const WebContentsCreatedCallback& callback) { 144 const WebContentsCreatedCallback& callback) {
148 std::string app_id; 145 std::string app_id;
149 if (!create_params.GetString(appview::kAppID, &app_id)) { 146 if (!create_params.GetString(appview::kAppID, &app_id)) {
150 callback.Run(NULL); 147 callback.Run(NULL);
151 return; 148 return;
152 } 149 }
153 150
154 const base::DictionaryValue* data = NULL; 151 const base::DictionaryValue* data = NULL;
155 if (!create_params.GetDictionary(appview::kData, &data)) { 152 if (!create_params.GetDictionary(appview::kData, &data)) {
156 callback.Run(NULL); 153 callback.Run(NULL);
157 return; 154 return;
158 } 155 }
159 156
160 ExtensionService* service = 157 const Extension* guest_extension = app_view_guest_delegate_->GetExtensionById(
Xi Han 2014/08/18 21:29:11 This part doesn't need to be moved to delegate, si
161 ExtensionSystem::Get(browser_context())->extension_service(); 158 browser_context(), app_id, false);
162 const Extension* guest_extension = service->GetExtensionById(app_id, false);
163 const Extension* embedder_extension = 159 const Extension* embedder_extension =
164 service->GetExtensionById(embedder_extension_id, false); 160 app_view_guest_delegate_->GetExtensionById(
161 browser_context(), embedder_extension_id, false);
165 162
166 if (!guest_extension || !guest_extension->is_platform_app() || 163 if (!guest_extension || !guest_extension->is_platform_app() ||
167 !embedder_extension | !embedder_extension->is_platform_app()) { 164 !embedder_extension | !embedder_extension->is_platform_app()) {
168 callback.Run(NULL); 165 callback.Run(NULL);
169 return; 166 return;
170 } 167 }
171 168
172 pending_response_map.Get().insert( 169 pending_response_map.Get().insert(
173 std::make_pair(GetGuestInstanceID(), 170 std::make_pair(GetGuestInstanceID(),
174 make_linked_ptr(new ResponseInfo( 171 make_linked_ptr(new ResponseInfo(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 247
251 scoped_ptr<base::DictionaryValue> embed_request(new base::DictionaryValue()); 248 scoped_ptr<base::DictionaryValue> embed_request(new base::DictionaryValue());
252 embed_request->SetInteger(appview::kGuestInstanceID, GetGuestInstanceID()); 249 embed_request->SetInteger(appview::kGuestInstanceID, GetGuestInstanceID());
253 embed_request->SetString(appview::kEmbedderID, embedder_extension_id()); 250 embed_request->SetString(appview::kEmbedderID, embedder_extension_id());
254 embed_request->Set(appview::kData, data.release()); 251 embed_request->Set(appview::kData, data.release());
255 AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( 252 AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent(
256 browser_context(), embed_request.Pass(), extension_host->extension()); 253 browser_context(), embed_request.Pass(), extension_host->extension());
257 } 254 }
258 255
259 } // namespace extensions 256 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698