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