| 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/shell/browser/shell_app_window.h" | 5 #include "extensions/shell/browser/shell_app_window.h" |
| 6 | 6 |
| 7 #include "content/public/browser/navigation_controller.h" | 7 #include "content/public/browser/navigation_controller.h" |
| 8 #include "content/public/browser/render_view_host.h" | 8 #include "content/public/browser/render_view_host.h" |
| 9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 #include "extensions/browser/view_type_utils.h" | 10 #include "extensions/browser/view_type_utils.h" |
| 11 #include "extensions/common/extension_messages.h" | 11 #include "extensions/common/extension_messages.h" |
| 12 #include "extensions/shell/browser/media_capture_util.h" |
| 12 #include "extensions/shell/browser/shell_extension_web_contents_observer.h" | 13 #include "extensions/shell/browser/shell_extension_web_contents_observer.h" |
| 13 #include "ipc/ipc_message_macros.h" | 14 #include "ipc/ipc_message_macros.h" |
| 14 | 15 |
| 15 using content::BrowserContext; | 16 using content::BrowserContext; |
| 16 using content::WebContents; | 17 using content::WebContents; |
| 17 | 18 |
| 18 namespace extensions { | 19 namespace extensions { |
| 19 | 20 |
| 20 ShellAppWindow::ShellAppWindow() { | 21 ShellAppWindow::ShellAppWindow() : extension_(NULL) { |
| 21 } | 22 } |
| 22 | 23 |
| 23 ShellAppWindow::~ShellAppWindow() { | 24 ShellAppWindow::~ShellAppWindow() { |
| 24 } | 25 } |
| 25 | 26 |
| 26 void ShellAppWindow::Init(BrowserContext* context, gfx::Size initial_size) { | 27 void ShellAppWindow::Init(BrowserContext* context, |
| 28 const Extension* extension, |
| 29 gfx::Size initial_size) { |
| 30 DCHECK(extension); |
| 31 DCHECK(context); |
| 32 extension_ = extension; |
| 27 extension_function_dispatcher_.reset( | 33 extension_function_dispatcher_.reset( |
| 28 new ExtensionFunctionDispatcher(context, this)); | 34 new ExtensionFunctionDispatcher(context, this)); |
| 29 | 35 |
| 30 // Create the web contents with an initial size to avoid a resize. | 36 // Create the web contents with an initial size to avoid a resize. |
| 31 WebContents::CreateParams create_params(context); | 37 WebContents::CreateParams create_params(context); |
| 32 create_params.initial_size = initial_size; | 38 create_params.initial_size = initial_size; |
| 33 web_contents_.reset(WebContents::Create(create_params)); | 39 web_contents_.reset(WebContents::Create(create_params)); |
| 34 | 40 |
| 35 content::WebContentsObserver::Observe(web_contents_.get()); | 41 content::WebContentsObserver::Observe(web_contents_.get()); |
| 42 web_contents_->SetDelegate(this); |
| 36 | 43 |
| 37 // Add support for extension startup. | 44 // Add support for extension startup. |
| 38 ShellExtensionWebContentsObserver::CreateForWebContents(web_contents_.get()); | 45 ShellExtensionWebContentsObserver::CreateForWebContents(web_contents_.get()); |
| 39 | 46 |
| 40 SetViewType(web_contents_.get(), VIEW_TYPE_APP_WINDOW); | 47 SetViewType(web_contents_.get(), VIEW_TYPE_APP_WINDOW); |
| 41 } | 48 } |
| 42 | 49 |
| 43 void ShellAppWindow::LoadURL(const GURL& url) { | 50 void ShellAppWindow::LoadURL(const GURL& url) { |
| 44 content::NavigationController::LoadURLParams params(url); | 51 content::NavigationController::LoadURLParams params(url); |
| 45 web_contents_->GetController().LoadURLWithParams(params); | 52 web_contents_->GetController().LoadURLWithParams(params); |
| 46 web_contents_->Focus(); | 53 web_contents_->Focus(); |
| 47 } | 54 } |
| 48 | 55 |
| 49 aura::Window* ShellAppWindow::GetNativeWindow() { | 56 aura::Window* ShellAppWindow::GetNativeWindow() { |
| 50 return web_contents_->GetNativeView(); | 57 return web_contents_->GetNativeView(); |
| 51 } | 58 } |
| 52 | 59 |
| 53 int ShellAppWindow::GetRenderViewRoutingID() { | 60 int ShellAppWindow::GetRenderViewRoutingID() { |
| 54 return web_contents_->GetRenderViewHost()->GetRoutingID(); | 61 return web_contents_->GetRenderViewHost()->GetRoutingID(); |
| 55 } | 62 } |
| 56 | 63 |
| 64 void ShellAppWindow::RequestMediaAccessPermission( |
| 65 content::WebContents* web_contents, |
| 66 const content::MediaStreamRequest& request, |
| 67 const content::MediaResponseCallback& callback) { |
| 68 // Allow access to the first microphone and/or camera. |
| 69 media_capture_util::GrantMediaStreamRequestWithFirstDevice( |
| 70 web_contents, request, callback, extension_); |
| 71 } |
| 72 |
| 57 bool ShellAppWindow::OnMessageReceived(const IPC::Message& message) { | 73 bool ShellAppWindow::OnMessageReceived(const IPC::Message& message) { |
| 58 bool handled = true; | 74 bool handled = true; |
| 59 IPC_BEGIN_MESSAGE_MAP(ShellAppWindow, message) | 75 IPC_BEGIN_MESSAGE_MAP(ShellAppWindow, message) |
| 60 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 76 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
| 61 IPC_MESSAGE_UNHANDLED(handled = false) | 77 IPC_MESSAGE_UNHANDLED(handled = false) |
| 62 IPC_END_MESSAGE_MAP() | 78 IPC_END_MESSAGE_MAP() |
| 63 return handled; | 79 return handled; |
| 64 } | 80 } |
| 65 | 81 |
| 66 content::WebContents* ShellAppWindow::GetAssociatedWebContents() const { | 82 content::WebContents* ShellAppWindow::GetAssociatedWebContents() const { |
| 67 return web_contents_.get(); | 83 return web_contents_.get(); |
| 68 } | 84 } |
| 69 | 85 |
| 70 void ShellAppWindow::OnRequest(const ExtensionHostMsg_Request_Params& params) { | 86 void ShellAppWindow::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
| 71 extension_function_dispatcher_->Dispatch(params, | 87 extension_function_dispatcher_->Dispatch(params, |
| 72 web_contents_->GetRenderViewHost()); | 88 web_contents_->GetRenderViewHost()); |
| 73 } | 89 } |
| 74 | 90 |
| 75 } // namespace extensions | 91 } // namespace extensions |
| OLD | NEW |