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

Side by Side Diff: chrome/browser/extensions/extension_host.cc

Issue 208020: Change the view mode when switching between moles and toolstrips, and (Closed)
Patch Set: build system workarounds Created 11 years, 3 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 (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/extension_host.h" 5 #include "chrome/browser/extensions/extension_host.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/browser_list.h" 10 #include "chrome/browser/browser_list.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 if (params.url.host() != extension_->id()) { 173 if (params.url.host() != extension_->id()) {
174 extension_function_dispatcher_.reset(NULL); 174 extension_function_dispatcher_.reset(NULL);
175 return; 175 return;
176 } 176 }
177 177
178 url_ = params.url; 178 url_ = params.url;
179 extension_function_dispatcher_.reset( 179 extension_function_dispatcher_.reset(
180 new ExtensionFunctionDispatcher(render_view_host_, this, url_)); 180 new ExtensionFunctionDispatcher(render_view_host_, this, url_));
181 } 181 }
182 182
183 void ExtensionHost::InsertCssIfToolstrip() { 183 void ExtensionHost::InsertThemeCSS() {
184 DCHECK(!is_background_page());
184 185
185 // TODO(erikkay): Make these ifdefs go away -- http://crbug.com/21939 186 static const base::StringPiece toolstrip_theme_css(
186 #if defined(TOOLKIT_VIEWS) 187 ResourceBundle::GetSharedInstance().GetRawDataResource(
187 ExtensionView* view = view_.get(); 188 IDR_EXTENSIONS_TOOLSTRIP_THEME_CSS));
188 if (!view)
189 return;
190 if (!view->is_toolstrip()) {
191 // No CSS injecting currently, but call SetDidInsertCSS to tell the view
192 // that it's OK to display.
193 view->SetDidInsertCSS(true);
194 return;
195 }
196 #elif defined(OS_LINUX) || defined(OS_MACOSX)
197 #if defined(OS_LINUX)
198 ExtensionViewGtk* view = view_.get();
199 #else
200 ExtensionViewMac* view = view_.get();
201 #endif
202 if (!view || !view->is_toolstrip())
203 return;
204 #endif
205 189
206 static const base::StringPiece toolstrip_css( 190 std::string css = toolstrip_theme_css.as_string();
207 ResourceBundle::GetSharedInstance().GetRawDataResource(
208 IDR_EXTENSIONS_TOOLSTRIP_CSS));
209
210 std::string css = toolstrip_css.as_string();
211 ThemeProvider* theme_provider = 191 ThemeProvider* theme_provider =
212 render_view_host()->process()->profile()->GetThemeProvider(); 192 render_view_host()->process()->profile()->GetThemeProvider();
213 193
214 SkColor text_color = theme_provider ? 194 SkColor text_color = theme_provider ?
215 theme_provider->GetColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT) : 195 theme_provider->GetColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT) :
216 SK_ColorBLACK; 196 SK_ColorBLACK;
217 197
218 std::string hex_color_string = StringPrintf( 198 std::string hex_color_string = StringPrintf(
219 "#%02x%02x%02x", SkColorGetR(text_color), 199 "#%02x%02x%02x", SkColorGetR(text_color),
220 SkColorGetG(text_color), 200 SkColorGetG(text_color),
221 SkColorGetB(text_color)); 201 SkColorGetB(text_color));
222 size_t pos = css.find(kToolstripTextColorSubstitution); 202 size_t pos = css.find(kToolstripTextColorSubstitution);
223 while (pos != std::string::npos) { 203 while (pos != std::string::npos) {
224 css.replace(pos, 12, hex_color_string); 204 css.replace(pos, 12, hex_color_string);
225 pos = css.find(kToolstripTextColorSubstitution); 205 pos = css.find(kToolstripTextColorSubstitution);
226 } 206 }
227 207
228 // TODO(erikkay) this injection should really happen in the renderer.
229 // When the Jerry's view type change lands, investigate moving this there.
230
231 // As a toolstrip, inject our toolstrip CSS to make it easier for toolstrips 208 // As a toolstrip, inject our toolstrip CSS to make it easier for toolstrips
232 // to blend in with the chrome UI. 209 // to blend in with the chrome UI.
233 render_view_host()->InsertCSSInWebFrame(L"", css, "ToolstripDefaultCss"); 210 render_view_host()->InsertCSSInWebFrame(L"", css, "ToolstripThemeCSS");
234 } 211 }
235 212
236 void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) { 213 void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) {
237 InsertCssIfToolstrip();
238 if (!did_stop_loading_) { 214 if (!did_stop_loading_) {
239 NotificationService::current()->Notify( 215 NotificationService::current()->Notify(
240 NotificationType::EXTENSION_HOST_DID_STOP_LOADING, 216 NotificationType::EXTENSION_HOST_DID_STOP_LOADING,
241 Source<Profile>(profile_), 217 Source<Profile>(profile_),
242 Details<ExtensionHost>(this)); 218 Details<ExtensionHost>(this));
243 did_stop_loading_ = true; 219 did_stop_loading_ = true;
244 } 220 }
221 if (extension_host_type_ == ViewType::EXTENSION_TOOLSTRIP ||
222 extension_host_type_ == ViewType::EXTENSION_MOLE) {
223 #if defined(TOOLKIT_VIEWS)
224 if (view_.get())
225 view_->DidStopLoading();
226 #endif
227 }
245 } 228 }
246 229
247 void ExtensionHost::DocumentAvailableInMainFrame(RenderViewHost* rvh) { 230 void ExtensionHost::DocumentAvailableInMainFrame(RenderViewHost* rvh) {
248 document_element_available_ = true; 231 document_element_available_ = true;
249 if (is_background_page()) 232 if (is_background_page())
250 extension_->SetBackgroundPageReady(); 233 extension_->SetBackgroundPageReady();
234 else
235 InsertThemeCSS();
251 } 236 }
252 237
253 void ExtensionHost::RunJavaScriptMessage(const std::wstring& message, 238 void ExtensionHost::RunJavaScriptMessage(const std::wstring& message,
254 const std::wstring& default_prompt, 239 const std::wstring& default_prompt,
255 const GURL& frame_url, 240 const GURL& frame_url,
256 const int flags, 241 const int flags,
257 IPC::Message* reply_msg, 242 IPC::Message* reply_msg,
258 bool* did_suppress_message) { 243 bool* did_suppress_message) {
259 // Automatically cancel the javascript alert (otherwise the renderer hangs 244 // Automatically cancel the javascript alert (otherwise the renderer hangs
260 // indefinitely). 245 // indefinitely).
(...skipping 10 matching lines...) Expand all
271 void ExtensionHost::ProcessDOMUIMessage(const std::string& message, 256 void ExtensionHost::ProcessDOMUIMessage(const std::string& message,
272 const std::string& content, 257 const std::string& content,
273 int request_id, 258 int request_id,
274 bool has_callback) { 259 bool has_callback) {
275 if (extension_function_dispatcher_.get()) { 260 if (extension_function_dispatcher_.get()) {
276 extension_function_dispatcher_->HandleRequest(message, content, request_id, 261 extension_function_dispatcher_->HandleRequest(message, content, request_id,
277 has_callback); 262 has_callback);
278 } 263 }
279 } 264 }
280 265
281 void ExtensionHost::DidInsertCSS() {
282 #if defined(TOOLKIT_VIEWS)
283 if (view_.get())
284 view_->SetDidInsertCSS(true);
285 #endif
286 }
287
288 RenderViewHostDelegate::View* ExtensionHost::GetViewDelegate() { 266 RenderViewHostDelegate::View* ExtensionHost::GetViewDelegate() {
289 return this; 267 return this;
290 } 268 }
291 269
292 void ExtensionHost::CreateNewWindow(int route_id, 270 void ExtensionHost::CreateNewWindow(int route_id,
293 base::WaitableEvent* modal_dialog_event) { 271 base::WaitableEvent* modal_dialog_event) {
294 delegate_view_helper_.CreateNewWindow( 272 delegate_view_helper_.CreateNewWindow(
295 route_id, modal_dialog_event, render_view_host()->process()->profile(), 273 route_id, modal_dialog_event, render_view_host()->process()->profile(),
296 site_instance(), DOMUIFactory::GetDOMUIType(url_)); 274 site_instance(), DOMUIFactory::GetDOMUIType(url_));
297 } 275 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 // valid here? 362 // valid here?
385 // NOTE(rafaelw): This can return NULL in some circumstances. In particular, 363 // NOTE(rafaelw): This can return NULL in some circumstances. In particular,
386 // a toolstrip or background_page onload chrome.tabs api call can make it 364 // a toolstrip or background_page onload chrome.tabs api call can make it
387 // into here before the browser is sufficiently initialized to return here. 365 // into here before the browser is sufficiently initialized to return here.
388 // A similar situation may arise during shutdown. 366 // A similar situation may arise during shutdown.
389 // TODO(rafaelw): Delay creation of background_page until the browser 367 // TODO(rafaelw): Delay creation of background_page until the browser
390 // is available. http://code.google.com/p/chromium/issues/detail?id=13284 368 // is available. http://code.google.com/p/chromium/issues/detail?id=13284
391 return browser; 369 return browser;
392 } 370 }
393 371
372 void ExtensionHost::SetRenderViewType(ViewType::Type type) {
373 DCHECK(type == ViewType::EXTENSION_MOLE ||
374 type == ViewType::EXTENSION_TOOLSTRIP);
375 extension_host_type_ = type;
376 render_view_host()->ViewTypeChanged(extension_host_type_);
377 }
378
394 ViewType::Type ExtensionHost::GetRenderViewType() const { 379 ViewType::Type ExtensionHost::GetRenderViewType() const {
395 return extension_host_type_; 380 return extension_host_type_;
396 } 381 }
397 382
398 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { 383 void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) {
399 // TODO(mpcomplete): This is duplicated in DidNavigate, which means that 384 // TODO(mpcomplete): This is duplicated in DidNavigate, which means that
400 // we'll create 2 EFDs for the first navigation. We should try to find a 385 // we'll create 2 EFDs for the first navigation. We should try to find a
401 // better way to unify them. 386 // better way to unify them.
402 // See http://code.google.com/p/chromium/issues/detail?id=18240 387 // See http://code.google.com/p/chromium/issues/detail?id=18240
403 extension_function_dispatcher_.reset( 388 extension_function_dispatcher_.reset(
404 new ExtensionFunctionDispatcher(render_view_host, this, url_)); 389 new ExtensionFunctionDispatcher(render_view_host, this, url_));
405 390
406 render_view_host->Send(new ViewMsg_EnableIntrinsicWidthChangedMode( 391 render_view_host->Send(new ViewMsg_EnableIntrinsicWidthChangedMode(
407 render_view_host->routing_id())); 392 render_view_host->routing_id()));
408 } 393 }
409 394
410 int ExtensionHost::GetBrowserWindowID() const { 395 int ExtensionHost::GetBrowserWindowID() const {
411 int window_id = -1; 396 int window_id = -1;
412 if (extension_host_type_ == ViewType::EXTENSION_TOOLSTRIP) { 397 if (extension_host_type_ == ViewType::EXTENSION_TOOLSTRIP) {
413 window_id = ExtensionTabUtil::GetWindowId( 398 window_id = ExtensionTabUtil::GetWindowId(
414 const_cast<ExtensionHost* >(this)->GetBrowser()); 399 const_cast<ExtensionHost* >(this)->GetBrowser());
415 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { 400 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) {
416 // Background page is not attached to any browser window, so pass -1. 401 // Background page is not attached to any browser window, so pass -1.
417 window_id = -1; 402 window_id = -1;
418 } else { 403 } else {
419 NOTREACHED(); 404 NOTREACHED();
420 } 405 }
421 return window_id; 406 return window_id;
422 } 407 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.h ('k') | chrome/browser/extensions/extension_shelf_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698