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

Side by Side Diff: chrome/browser/extensions/api/tabs/ash_panel_contents.cc

Issue 1169223002: [Extensions] Clean up the handling of ExtensionHostMsg_Request (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master Created 5 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extensions/api/tabs/ash_panel_contents.h" 5 #include "chrome/browser/extensions/api/tabs/ash_panel_contents.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 9 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
10 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" 10 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h"
11 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" 11 #include "chrome/browser/extensions/api/tabs/windows_event_router.h"
12 #include "chrome/browser/extensions/extension_tab_util.h" 12 #include "chrome/browser/extensions/extension_tab_util.h"
13 #include "chrome/browser/extensions/window_controller_list.h" 13 #include "chrome/browser/extensions/window_controller_list.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/sessions/session_tab_helper.h" 15 #include "chrome/browser/sessions/session_tab_helper.h"
16 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/site_instance.h" 17 #include "content/public/browser/site_instance.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "extensions/browser/app_window/native_app_window.h" 19 #include "extensions/browser/app_window/native_app_window.h"
20 #include "extensions/common/extension.h" 20 #include "extensions/common/extension.h"
21 #include "extensions/common/extension_messages.h"
22 #include "ui/gfx/image/image.h" 21 #include "ui/gfx/image/image.h"
23 22
24 using extensions::AppWindow; 23 using extensions::AppWindow;
25 using extensions::NativeAppWindow; 24 using extensions::NativeAppWindow;
26 25
27 // AshPanelWindowController ---------------------------------------------------- 26 // AshPanelWindowController ----------------------------------------------------
28 27
29 // This class enables an AppWindow instance to be accessed (to a limited 28 // This class enables an AppWindow instance to be accessed (to a limited
30 // extent) via the chrome.windows and chrome.tabs API. This is a temporary 29 // extent) via the chrome.windows and chrome.tabs API. This is a temporary
31 // bridge to support instantiating AppWindows from v1 apps, specifically 30 // bridge to support instantiating AppWindows from v1 apps, specifically
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 160
162 AshPanelContents::AshPanelContents(AppWindow* host) : host_(host) {} 161 AshPanelContents::AshPanelContents(AppWindow* host) : host_(host) {}
163 162
164 AshPanelContents::~AshPanelContents() { 163 AshPanelContents::~AshPanelContents() {
165 } 164 }
166 165
167 void AshPanelContents::Initialize(content::BrowserContext* context, 166 void AshPanelContents::Initialize(content::BrowserContext* context,
168 const GURL& url) { 167 const GURL& url) {
169 url_ = url; 168 url_ = url;
170 169
171 extension_function_dispatcher_.reset(
172 new extensions::ExtensionFunctionDispatcher(context, this));
173
174 web_contents_.reset( 170 web_contents_.reset(
175 content::WebContents::Create(content::WebContents::CreateParams( 171 content::WebContents::Create(content::WebContents::CreateParams(
176 context, content::SiteInstance::CreateForURL(context, url_)))); 172 context, content::SiteInstance::CreateForURL(context, url_))));
177 173
178 // Needed to give the web contents a Window ID. Extension APIs expect web 174 // Needed to give the web contents a Window ID. Extension APIs expect web
179 // contents to have a Window ID. Also required for FaviconDriver to correctly 175 // contents to have a Window ID. Also required for FaviconDriver to correctly
180 // set the window icon and title. 176 // set the window icon and title.
181 SessionTabHelper::CreateForWebContents(web_contents_.get()); 177 SessionTabHelper::CreateForWebContents(web_contents_.get());
182 SessionTabHelper::FromWebContents(web_contents_.get())->SetWindowID( 178 SessionTabHelper::FromWebContents(web_contents_.get())->SetWindowID(
183 host_->session_id()); 179 host_->session_id());
184 180
185 // Responsible for loading favicons for the Launcher, which uses different 181 // Responsible for loading favicons for the Launcher, which uses different
186 // logic than the FaviconDriver associated with web_contents_ (instantiated in 182 // logic than the FaviconDriver associated with web_contents_ (instantiated in
187 // AppWindow::Init()) 183 // AppWindow::Init())
188 launcher_favicon_loader_.reset( 184 launcher_favicon_loader_.reset(
189 new LauncherFaviconLoader(this, web_contents_.get())); 185 new LauncherFaviconLoader(this, web_contents_.get()));
190
191 content::WebContentsObserver::Observe(web_contents_.get());
192 } 186 }
193 187
194 void AshPanelContents::LoadContents(int32 creator_process_id) { 188 void AshPanelContents::LoadContents(int32 creator_process_id) {
195 // This must be created after the native window has been created. 189 // This must be created after the native window has been created.
196 window_controller_.reset(new AshPanelWindowController( 190 window_controller_.reset(new AshPanelWindowController(
197 host_, Profile::FromBrowserContext(host_->browser_context()))); 191 host_, Profile::FromBrowserContext(host_->browser_context())));
198 192
199 web_contents_->GetController().LoadURL( 193 web_contents_->GetController().LoadURL(
200 url_, content::Referrer(), ui::PAGE_TRANSITION_LINK, 194 url_, content::Referrer(), ui::PAGE_TRANSITION_LINK,
201 std::string()); 195 std::string());
202 } 196 }
203 197
204 void AshPanelContents::NativeWindowChanged(NativeAppWindow* native_app_window) { 198 void AshPanelContents::NativeWindowChanged(NativeAppWindow* native_app_window) {
205 if (window_controller_) 199 if (window_controller_)
206 window_controller_->NativeWindowChanged(); 200 window_controller_->NativeWindowChanged();
207 } 201 }
208 202
209 void AshPanelContents::NativeWindowClosed() { 203 void AshPanelContents::NativeWindowClosed() {
210 } 204 }
211 205
212 void AshPanelContents::DispatchWindowShownForTests() const { 206 void AshPanelContents::DispatchWindowShownForTests() const {
213 } 207 }
214 208
215 content::WebContents* AshPanelContents::GetWebContents() const { 209 content::WebContents* AshPanelContents::GetWebContents() const {
216 return web_contents_.get(); 210 return web_contents_.get();
217 } 211 }
218 212
213 extensions::WindowController* AshPanelContents::GetWindowController() const {
214 return window_controller_.get();
215 }
216
219 void AshPanelContents::FaviconUpdated() { 217 void AshPanelContents::FaviconUpdated() {
220 gfx::Image new_image = gfx::Image::CreateFrom1xBitmap( 218 gfx::Image new_image = gfx::Image::CreateFrom1xBitmap(
221 launcher_favicon_loader_->GetFavicon()); 219 launcher_favicon_loader_->GetFavicon());
222 host_->UpdateAppIcon(new_image); 220 host_->UpdateAppIcon(new_image);
223 } 221 }
224
225 bool AshPanelContents::OnMessageReceived(const IPC::Message& message) {
226 bool handled = true;
227 IPC_BEGIN_MESSAGE_MAP(AshPanelContents, message)
228 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
229 IPC_MESSAGE_UNHANDLED(handled = false)
230 IPC_END_MESSAGE_MAP()
231 return handled;
232 }
233
234 extensions::WindowController*
235 AshPanelContents::GetExtensionWindowController() const {
236 return window_controller_.get();
237 }
238
239 content::WebContents* AshPanelContents::GetAssociatedWebContents() const {
240 return web_contents_.get();
241 }
242
243 void AshPanelContents::OnRequest(
244 const ExtensionHostMsg_Request_Params& params) {
245 extension_function_dispatcher_->Dispatch(
246 params, web_contents_->GetRenderViewHost());
247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698