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

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

Issue 175025: Add a bare-bones extension shelf that displays extension items on OS X. (Closed)
Patch Set: Merge ToT, address more comments 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 void ExtensionHost::CreateView(Browser* browser) { 65 void ExtensionHost::CreateView(Browser* browser) {
66 #if defined(TOOLKIT_VIEWS) 66 #if defined(TOOLKIT_VIEWS)
67 view_.reset(new ExtensionView(this, browser)); 67 view_.reset(new ExtensionView(this, browser));
68 // We own |view_|, so don't auto delete when it's removed from the view 68 // We own |view_|, so don't auto delete when it's removed from the view
69 // hierarchy. 69 // hierarchy.
70 view_->SetParentOwned(false); 70 view_->SetParentOwned(false);
71 #elif defined(OS_LINUX) 71 #elif defined(OS_LINUX)
72 view_.reset(new ExtensionViewGtk(this, browser)); 72 view_.reset(new ExtensionViewGtk(this, browser));
73 view_->Init(); 73 view_->Init();
74 #elif defined(OS_MACOSX)
75 view_.reset(new ExtensionViewMac(this, browser));
76 view_->Init();
74 #else 77 #else
75 // TODO(port) 78 // TODO(port)
76 NOTREACHED(); 79 NOTREACHED();
77 #endif 80 #endif
78 } 81 }
79 82
80 RenderProcessHost* ExtensionHost::render_process_host() const { 83 RenderProcessHost* ExtensionHost::render_process_host() const {
81 return render_view_host_->process(); 84 return render_view_host_->process();
82 } 85 }
83 86
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 126
124 void ExtensionHost::Observe(NotificationType type, 127 void ExtensionHost::Observe(NotificationType type,
125 const NotificationSource& source, 128 const NotificationSource& source,
126 const NotificationDetails& details) { 129 const NotificationDetails& details) {
127 DCHECK(type == NotificationType::EXTENSION_BACKGROUND_PAGE_READY); 130 DCHECK(type == NotificationType::EXTENSION_BACKGROUND_PAGE_READY);
128 DCHECK(extension_->GetBackgroundPageReady()); 131 DCHECK(extension_->GetBackgroundPageReady());
129 NavigateToURL(url_); 132 NavigateToURL(url_);
130 } 133 }
131 134
132 void ExtensionHost::UpdatePreferredWidth(int pref_width) { 135 void ExtensionHost::UpdatePreferredWidth(int pref_width) {
133 #if defined(TOOLKIT_VIEWS) || defined(OS_LINUX)
134 if (view_.get()) 136 if (view_.get())
135 view_->UpdatePreferredWidth(pref_width); 137 view_->UpdatePreferredWidth(pref_width);
136 #endif
137 } 138 }
138 139
139 void ExtensionHost::RenderViewGone(RenderViewHost* render_view_host) { 140 void ExtensionHost::RenderViewGone(RenderViewHost* render_view_host) {
140 DCHECK_EQ(render_view_host_, render_view_host); 141 DCHECK_EQ(render_view_host_, render_view_host);
141 NotificationService::current()->Notify( 142 NotificationService::current()->Notify(
142 NotificationType::EXTENSION_PROCESS_CRASHED, 143 NotificationType::EXTENSION_PROCESS_CRASHED,
143 Source<ExtensionsService>(profile_->GetExtensionsService()), 144 Source<ExtensionsService>(profile_->GetExtensionsService()),
144 Details<ExtensionHost>(this)); 145 Details<ExtensionHost>(this));
145 } 146 }
146 147
(...skipping 26 matching lines...) Expand all
173 extension_function_dispatcher_.reset(NULL); 174 extension_function_dispatcher_.reset(NULL);
174 return; 175 return;
175 } 176 }
176 177
177 url_ = params.url; 178 url_ = params.url;
178 extension_function_dispatcher_.reset( 179 extension_function_dispatcher_.reset(
179 new ExtensionFunctionDispatcher(render_view_host_, this, url_)); 180 new ExtensionFunctionDispatcher(render_view_host_, this, url_));
180 } 181 }
181 182
182 void ExtensionHost::InsertCssIfToolstrip() { 183 void ExtensionHost::InsertCssIfToolstrip() {
184
185 // TODO(erikkay): Make these ifdefs go away -- http://crbug.com/21939
183 #if defined(TOOLKIT_VIEWS) 186 #if defined(TOOLKIT_VIEWS)
184 ExtensionView* view = view_.get(); 187 ExtensionView* view = view_.get();
185 if (!view) 188 if (!view)
186 return; 189 return;
187 if (!view->is_toolstrip()) { 190 if (!view->is_toolstrip()) {
188 // No CSS injecting currently, but call SetDidInsertCSS to tell the view 191 // No CSS injecting currently, but call SetDidInsertCSS to tell the view
189 // that it's OK to display. 192 // that it's OK to display.
190 view->SetDidInsertCSS(true); 193 view->SetDidInsertCSS(true);
191 return; 194 return;
192 } 195 }
193 #elif defined(OS_LINUX) 196 #elif defined(OS_LINUX) || defined(OS_MACOSX)
197 #if defined(OS_LINUX)
194 ExtensionViewGtk* view = view_.get(); 198 ExtensionViewGtk* view = view_.get();
199 #else
200 ExtensionViewMac* view = view_.get();
201 #endif
195 if (!view || !view->is_toolstrip()) 202 if (!view || !view->is_toolstrip())
196 return; 203 return;
197 #endif 204 #endif
198 205
199 static const base::StringPiece toolstrip_css( 206 static const base::StringPiece toolstrip_css(
200 ResourceBundle::GetSharedInstance().GetRawDataResource( 207 ResourceBundle::GetSharedInstance().GetRawDataResource(
201 IDR_EXTENSIONS_TOOLSTRIP_CSS)); 208 IDR_EXTENSIONS_TOOLSTRIP_CSS));
202 209
203 std::string css = toolstrip_css.as_string(); 210 std::string css = toolstrip_css.as_string();
204 ThemeProvider* theme_provider = 211 ThemeProvider* theme_provider =
205 render_view_host()->process()->profile()->GetThemeProvider(); 212 render_view_host()->process()->profile()->GetThemeProvider();
206 213
207 SkColor text_color = theme_provider ? 214 SkColor text_color = theme_provider ?
208 theme_provider->GetColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT) : 215 theme_provider->GetColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT) :
209 SK_ColorBLACK; 216 SK_ColorBLACK;
210 217
211 std::string hex_color_string = StringPrintf( 218 std::string hex_color_string = StringPrintf(
212 "#%02x%02x%02x", SkColorGetR(text_color), 219 "#%02x%02x%02x", SkColorGetR(text_color),
213 SkColorGetG(text_color), 220 SkColorGetG(text_color),
214 SkColorGetB(text_color)); 221 SkColorGetB(text_color));
215 size_t pos = css.find(kToolstripTextColorSubstitution); 222 size_t pos = css.find(kToolstripTextColorSubstitution);
216 while (pos != std::string::npos) { 223 while (pos != std::string::npos) {
217 css.replace(pos, 12, hex_color_string); 224 css.replace(pos, 12, hex_color_string);
218 pos = css.find(kToolstripTextColorSubstitution); 225 pos = css.find(kToolstripTextColorSubstitution);
219 } 226 }
220 227
221 #if defined(TOOLKIT_VIEWS) || defined(OS_LINUX)
222 // TODO(erikkay) this injection should really happen in the renderer. 228 // TODO(erikkay) this injection should really happen in the renderer.
223 // When the Jerry's view type change lands, investigate moving this there. 229 // When the Jerry's view type change lands, investigate moving this there.
224 230
225 // As a toolstrip, inject our toolstrip CSS to make it easier for toolstrips 231 // As a toolstrip, inject our toolstrip CSS to make it easier for toolstrips
226 // to blend in with the chrome UI. 232 // to blend in with the chrome UI.
227 render_view_host()->InsertCSSInWebFrame(L"", css, "ToolstripDefaultCss"); 233 render_view_host()->InsertCSSInWebFrame(L"", css, "ToolstripDefaultCss");
228 #endif
229 } 234 }
230 235
231 void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) { 236 void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) {
232 InsertCssIfToolstrip(); 237 InsertCssIfToolstrip();
233 if (!did_stop_loading_) { 238 if (!did_stop_loading_) {
234 NotificationService::current()->Notify( 239 NotificationService::current()->Notify(
235 NotificationType::EXTENSION_HOST_DID_STOP_LOADING, 240 NotificationType::EXTENSION_HOST_DID_STOP_LOADING,
236 Source<Profile>(profile_), 241 Source<Profile>(profile_),
237 Details<ExtensionHost>(this)); 242 Details<ExtensionHost>(this));
238 did_stop_loading_ = true; 243 did_stop_loading_ = true;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 } 360 }
356 361
357 void ExtensionHost::HandleMouseLeave() { 362 void ExtensionHost::HandleMouseLeave() {
358 #if defined(OS_WIN) 363 #if defined(OS_WIN)
359 if (view_.get()) 364 if (view_.get())
360 view_->HandleMouseLeave(); 365 view_->HandleMouseLeave();
361 #endif 366 #endif
362 } 367 }
363 368
364 Browser* ExtensionHost::GetBrowser() { 369 Browser* ExtensionHost::GetBrowser() {
365 #if defined(OS_WIN) || defined(OS_LINUX)
366 if (view_.get()) 370 if (view_.get())
367 return view_->browser(); 371 return view_->browser();
368 #endif 372
369 Profile* profile = render_view_host()->process()->profile(); 373 Profile* profile = render_view_host()->process()->profile();
370 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); 374 Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
371 375
372 // It's possible for a browser to exist, but to have never been active. 376 // It's possible for a browser to exist, but to have never been active.
373 // This can happen if you launch the browser on a machine without an active 377 // This can happen if you launch the browser on a machine without an active
374 // desktop (a headless buildbot) or if you quickly give another app focus 378 // desktop (a headless buildbot) or if you quickly give another app focus
375 // at launch time. This is easy to do with browser_tests. 379 // at launch time. This is easy to do with browser_tests.
376 if (!browser) 380 if (!browser)
377 browser = BrowserList::FindBrowserWithProfile(profile); 381 browser = BrowserList::FindBrowserWithProfile(profile);
378 382
(...skipping 30 matching lines...) Expand all
409 window_id = ExtensionTabUtil::GetWindowId( 413 window_id = ExtensionTabUtil::GetWindowId(
410 const_cast<ExtensionHost* >(this)->GetBrowser()); 414 const_cast<ExtensionHost* >(this)->GetBrowser());
411 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { 415 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) {
412 // Background page is not attached to any browser window, so pass -1. 416 // Background page is not attached to any browser window, so pass -1.
413 window_id = -1; 417 window_id = -1;
414 } else { 418 } else {
415 NOTREACHED(); 419 NOTREACHED();
416 } 420 }
417 return window_id; 421 return window_id;
418 } 422 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.h ('k') | chrome/browser/renderer_host/render_widget_host_view_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698