| 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 "extensions/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 "content/public/browser/render_view_host.h" | 8 #include "content/public/browser/render_view_host.h" |
| 9 #include "content/public/common/renderer_preferences.h" | 9 #include "content/public/common/renderer_preferences.h" |
| 10 #include "extensions/browser/api/app_runtime/app_runtime_api.h" | 10 #include "extensions/browser/api/app_runtime/app_runtime_api.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 response_map->erase(guest_instance_id); | 86 response_map->erase(guest_instance_id); |
| 87 return true; | 87 return true; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // static | 90 // static |
| 91 GuestViewBase* AppViewGuest::Create(content::BrowserContext* browser_context, | 91 GuestViewBase* AppViewGuest::Create(content::BrowserContext* browser_context, |
| 92 int guest_instance_id) { | 92 int guest_instance_id) { |
| 93 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 93 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 94 extensions::switches::kEnableAppView)) { | 94 extensions::switches::kEnableAppView)) { |
| 95 return NULL; | 95 return nullptr; |
| 96 } | 96 } |
| 97 return new AppViewGuest(browser_context, guest_instance_id); | 97 return new AppViewGuest(browser_context, guest_instance_id); |
| 98 } | 98 } |
| 99 | 99 |
| 100 AppViewGuest::AppViewGuest(content::BrowserContext* browser_context, | 100 AppViewGuest::AppViewGuest(content::BrowserContext* browser_context, |
| 101 int guest_instance_id) | 101 int guest_instance_id) |
| 102 : GuestView<AppViewGuest>(browser_context, guest_instance_id), | 102 : GuestView<AppViewGuest>(browser_context, guest_instance_id), |
| 103 app_view_guest_delegate_( | 103 app_view_guest_delegate_( |
| 104 ExtensionsAPIClient::Get()->CreateAppViewGuestDelegate()), | 104 ExtensionsAPIClient::Get()->CreateAppViewGuestDelegate()), |
| 105 weak_ptr_factory_(this) { | 105 weak_ptr_factory_(this) { |
| 106 } | 106 } |
| 107 | 107 |
| 108 AppViewGuest::~AppViewGuest() { | 108 AppViewGuest::~AppViewGuest() { |
| 109 } | 109 } |
| 110 | 110 |
| 111 WindowController* AppViewGuest::GetExtensionWindowController() const { | 111 WindowController* AppViewGuest::GetExtensionWindowController() const { |
| 112 return NULL; | 112 return nullptr; |
| 113 } | 113 } |
| 114 | 114 |
| 115 content::WebContents* AppViewGuest::GetAssociatedWebContents() const { | 115 content::WebContents* AppViewGuest::GetAssociatedWebContents() const { |
| 116 return web_contents(); | 116 return web_contents(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool AppViewGuest::OnMessageReceived(const IPC::Message& message) { | 119 bool AppViewGuest::OnMessageReceived(const IPC::Message& message) { |
| 120 bool handled = true; | 120 bool handled = true; |
| 121 IPC_BEGIN_MESSAGE_MAP(AppViewGuest, message) | 121 IPC_BEGIN_MESSAGE_MAP(AppViewGuest, message) |
| 122 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 122 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 140 return IDS_EXTENSION_TASK_MANAGER_APPVIEW_TAG_PREFIX; | 140 return IDS_EXTENSION_TASK_MANAGER_APPVIEW_TAG_PREFIX; |
| 141 } | 141 } |
| 142 | 142 |
| 143 void AppViewGuest::CreateWebContents( | 143 void AppViewGuest::CreateWebContents( |
| 144 const std::string& embedder_extension_id, | 144 const std::string& embedder_extension_id, |
| 145 int embedder_render_process_id, | 145 int embedder_render_process_id, |
| 146 const base::DictionaryValue& create_params, | 146 const base::DictionaryValue& create_params, |
| 147 const WebContentsCreatedCallback& callback) { | 147 const WebContentsCreatedCallback& callback) { |
| 148 std::string app_id; | 148 std::string app_id; |
| 149 if (!create_params.GetString(appview::kAppID, &app_id)) { | 149 if (!create_params.GetString(appview::kAppID, &app_id)) { |
| 150 callback.Run(NULL); | 150 callback.Run(nullptr); |
| 151 return; | 151 return; |
| 152 } | 152 } |
| 153 | 153 |
| 154 const base::DictionaryValue* data = NULL; | 154 const base::DictionaryValue* data = nullptr; |
| 155 if (!create_params.GetDictionary(appview::kData, &data)) { | 155 if (!create_params.GetDictionary(appview::kData, &data)) { |
| 156 callback.Run(NULL); | 156 callback.Run(nullptr); |
| 157 return; | 157 return; |
| 158 } | 158 } |
| 159 | 159 |
| 160 const ExtensionSet& enabled_extensions = | 160 const ExtensionSet& enabled_extensions = |
| 161 ExtensionRegistry::Get(browser_context())->enabled_extensions(); | 161 ExtensionRegistry::Get(browser_context())->enabled_extensions(); |
| 162 const Extension* guest_extension = enabled_extensions.GetByID(app_id); | 162 const Extension* guest_extension = enabled_extensions.GetByID(app_id); |
| 163 const Extension* embedder_extension = | 163 const Extension* embedder_extension = |
| 164 enabled_extensions.GetByID(embedder_extension_id); | 164 enabled_extensions.GetByID(embedder_extension_id); |
| 165 | 165 |
| 166 if (!guest_extension || !guest_extension->is_platform_app() || | 166 if (!guest_extension || !guest_extension->is_platform_app() || |
| 167 !embedder_extension | !embedder_extension->is_platform_app()) { | 167 !embedder_extension | !embedder_extension->is_platform_app()) { |
| 168 callback.Run(NULL); | 168 callback.Run(nullptr); |
| 169 return; | 169 return; |
| 170 } | 170 } |
| 171 | 171 |
| 172 pending_response_map.Get().insert( | 172 pending_response_map.Get().insert( |
| 173 std::make_pair(guest_instance_id(), | 173 std::make_pair(guest_instance_id(), |
| 174 make_linked_ptr(new ResponseInfo( | 174 make_linked_ptr(new ResponseInfo( |
| 175 guest_extension, | 175 guest_extension, |
| 176 weak_ptr_factory_.GetWeakPtr(), | 176 weak_ptr_factory_.GetWeakPtr(), |
| 177 callback)))); | 177 callback)))); |
| 178 | 178 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 void AppViewGuest::OnRequest(const ExtensionHostMsg_Request_Params& params) { | 214 void AppViewGuest::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
| 215 extension_function_dispatcher_->Dispatch(params, | 215 extension_function_dispatcher_->Dispatch(params, |
| 216 web_contents()->GetRenderViewHost()); | 216 web_contents()->GetRenderViewHost()); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void AppViewGuest::CompleteCreateWebContents( | 219 void AppViewGuest::CompleteCreateWebContents( |
| 220 const GURL& url, | 220 const GURL& url, |
| 221 const Extension* guest_extension, | 221 const Extension* guest_extension, |
| 222 const WebContentsCreatedCallback& callback) { | 222 const WebContentsCreatedCallback& callback) { |
| 223 if (!url.is_valid()) { | 223 if (!url.is_valid()) { |
| 224 callback.Run(NULL); | 224 callback.Run(nullptr); |
| 225 return; | 225 return; |
| 226 } | 226 } |
| 227 url_ = url; | 227 url_ = url; |
| 228 guest_extension_id_ = guest_extension->id(); | 228 guest_extension_id_ = guest_extension->id(); |
| 229 | 229 |
| 230 WebContents::CreateParams params( | 230 WebContents::CreateParams params( |
| 231 browser_context(), | 231 browser_context(), |
| 232 content::SiteInstance::CreateForURL(browser_context(), | 232 content::SiteInstance::CreateForURL(browser_context(), |
| 233 guest_extension->url())); | 233 guest_extension->url())); |
| 234 params.guest_delegate = this; | 234 params.guest_delegate = this; |
| 235 callback.Run(WebContents::Create(params)); | 235 callback.Run(WebContents::Create(params)); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void AppViewGuest::LaunchAppAndFireEvent( | 238 void AppViewGuest::LaunchAppAndFireEvent( |
| 239 scoped_ptr<base::DictionaryValue> data, | 239 scoped_ptr<base::DictionaryValue> data, |
| 240 const WebContentsCreatedCallback& callback, | 240 const WebContentsCreatedCallback& callback, |
| 241 ExtensionHost* extension_host) { | 241 ExtensionHost* extension_host) { |
| 242 ExtensionSystem* system = ExtensionSystem::Get(browser_context()); | 242 ExtensionSystem* system = ExtensionSystem::Get(browser_context()); |
| 243 bool has_event_listener = system->event_router()->ExtensionHasEventListener( | 243 bool has_event_listener = system->event_router()->ExtensionHasEventListener( |
| 244 extension_host->extension()->id(), | 244 extension_host->extension()->id(), |
| 245 app_runtime::OnEmbedRequested::kEventName); | 245 app_runtime::OnEmbedRequested::kEventName); |
| 246 if (!has_event_listener) { | 246 if (!has_event_listener) { |
| 247 callback.Run(NULL); | 247 callback.Run(nullptr); |
| 248 return; | 248 return; |
| 249 } | 249 } |
| 250 | 250 |
| 251 scoped_ptr<base::DictionaryValue> embed_request(new base::DictionaryValue()); | 251 scoped_ptr<base::DictionaryValue> embed_request(new base::DictionaryValue()); |
| 252 embed_request->SetInteger(appview::kGuestInstanceID, guest_instance_id()); | 252 embed_request->SetInteger(appview::kGuestInstanceID, guest_instance_id()); |
| 253 embed_request->SetString(appview::kEmbedderID, embedder_extension_id()); | 253 embed_request->SetString(appview::kEmbedderID, embedder_extension_id()); |
| 254 embed_request->Set(appview::kData, data.release()); | 254 embed_request->Set(appview::kData, data.release()); |
| 255 AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( | 255 AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( |
| 256 browser_context(), embed_request.Pass(), extension_host->extension()); | 256 browser_context(), embed_request.Pass(), extension_host->extension()); |
| 257 } | 257 } |
| 258 | 258 |
| 259 } // namespace extensions | 259 } // namespace extensions |
| OLD | NEW |