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

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 562533002: Remove deprecated extension notification from Browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed extra code Created 6 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
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // defined(OS_WIN) 10 #endif // defined(OS_WIN)
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 #include "content/public/browser/render_view_host.h" 174 #include "content/public/browser/render_view_host.h"
175 #include "content/public/browser/render_widget_host_view.h" 175 #include "content/public/browser/render_widget_host_view.h"
176 #include "content/public/browser/site_instance.h" 176 #include "content/public/browser/site_instance.h"
177 #include "content/public/browser/user_metrics.h" 177 #include "content/public/browser/user_metrics.h"
178 #include "content/public/browser/web_contents.h" 178 #include "content/public/browser/web_contents.h"
179 #include "content/public/common/content_switches.h" 179 #include "content/public/common/content_switches.h"
180 #include "content/public/common/page_zoom.h" 180 #include "content/public/common/page_zoom.h"
181 #include "content/public/common/renderer_preferences.h" 181 #include "content/public/common/renderer_preferences.h"
182 #include "content/public/common/webplugininfo.h" 182 #include "content/public/common/webplugininfo.h"
183 #include "extensions/browser/extension_prefs.h" 183 #include "extensions/browser/extension_prefs.h"
184 #include "extensions/browser/extension_registry.h"
184 #include "extensions/browser/extension_system.h" 185 #include "extensions/browser/extension_system.h"
185 #include "extensions/common/constants.h" 186 #include "extensions/common/constants.h"
186 #include "extensions/common/extension.h" 187 #include "extensions/common/extension.h"
187 #include "extensions/common/manifest_handlers/background_info.h" 188 #include "extensions/common/manifest_handlers/background_info.h"
188 #include "net/base/filename_util.h" 189 #include "net/base/filename_util.h"
189 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 190 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
190 #include "net/cookies/cookie_monster.h" 191 #include "net/cookies/cookie_monster.h"
191 #include "net/url_request/url_request_context.h" 192 #include "net/url_request/url_request_context.h"
192 #include "third_party/WebKit/public/web/WebWindowFeatures.h" 193 #include "third_party/WebKit/public/web/WebWindowFeatures.h"
193 #include "ui/base/l10n/l10n_util.h" 194 #include "ui/base/l10n/l10n_util.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 }; 326 };
326 327
327 /////////////////////////////////////////////////////////////////////////////// 328 ///////////////////////////////////////////////////////////////////////////////
328 // Browser, Constructors, Creation, Showing: 329 // Browser, Constructors, Creation, Showing:
329 330
330 Browser::Browser(const CreateParams& params) 331 Browser::Browser(const CreateParams& params)
331 : type_(params.type), 332 : type_(params.type),
332 profile_(params.profile), 333 profile_(params.profile),
333 window_(NULL), 334 window_(NULL),
334 tab_strip_model_delegate_(new chrome::BrowserTabStripModelDelegate(this)), 335 tab_strip_model_delegate_(new chrome::BrowserTabStripModelDelegate(this)),
335 tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(), 336 tab_strip_model_(
336 params.profile)), 337 new TabStripModel(tab_strip_model_delegate_.get(), params.profile)),
337 app_name_(params.app_name), 338 app_name_(params.app_name),
338 is_trusted_source_(params.trusted_source), 339 is_trusted_source_(params.trusted_source),
339 cancel_download_confirmation_state_(NOT_PROMPTED), 340 cancel_download_confirmation_state_(NOT_PROMPTED),
340 override_bounds_(params.initial_bounds), 341 override_bounds_(params.initial_bounds),
341 initial_show_state_(params.initial_show_state), 342 initial_show_state_(params.initial_show_state),
342 is_session_restore_(params.is_session_restore), 343 is_session_restore_(params.is_session_restore),
343 host_desktop_type_(BrowserWindow::AdjustHostDesktopType( 344 host_desktop_type_(
344 params.host_desktop_type)), 345 BrowserWindow::AdjustHostDesktopType(params.host_desktop_type)),
345 content_setting_bubble_model_delegate_( 346 content_setting_bubble_model_delegate_(
346 new BrowserContentSettingBubbleModelDelegate(this)), 347 new BrowserContentSettingBubbleModelDelegate(this)),
347 toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)), 348 toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)),
348 tab_restore_service_delegate_(new BrowserTabRestoreServiceDelegate(this)), 349 tab_restore_service_delegate_(new BrowserTabRestoreServiceDelegate(this)),
349 synced_window_delegate_(new BrowserSyncedWindowDelegate(this)), 350 synced_window_delegate_(new BrowserSyncedWindowDelegate(this)),
350 bookmark_bar_state_(BookmarkBar::HIDDEN), 351 bookmark_bar_state_(BookmarkBar::HIDDEN),
351 command_controller_(new chrome::BrowserCommandController(this)), 352 command_controller_(new chrome::BrowserCommandController(this)),
352 window_has_shown_(false), 353 window_has_shown_(false),
353 chrome_updater_factory_(this), 354 chrome_updater_factory_(this),
354 weak_factory_(this), 355 weak_factory_(this),
355 translate_driver_observer_( 356 translate_driver_observer_(
356 new BrowserContentTranslateDriverObserver(this)) { 357 new BrowserContentTranslateDriverObserver(this)),
358 extension_registry_observer_(this) {
357 // If this causes a crash then a window is being opened using a profile type 359 // If this causes a crash then a window is being opened using a profile type
358 // that is disallowed by policy. The crash prevents the disabled window type 360 // that is disallowed by policy. The crash prevents the disabled window type
359 // from opening at all, but the path that triggered it should be fixed. 361 // from opening at all, but the path that triggered it should be fixed.
360 CHECK(IncognitoModePrefs::CanOpenBrowser(profile_)); 362 CHECK(IncognitoModePrefs::CanOpenBrowser(profile_));
361 CHECK(!profile_->IsGuestSession() || profile_->IsOffTheRecord()) 363 CHECK(!profile_->IsGuestSession() || profile_->IsOffTheRecord())
362 << "Only off the record browser may be opened in guest mode"; 364 << "Only off the record browser may be opened in guest mode";
363 365
364 // TODO(jeremy): Move to initializer list once flag is removed. 366 // TODO(jeremy): Move to initializer list once flag is removed.
365 if (IsFastTabUnloadEnabled()) 367 if (IsFastTabUnloadEnabled())
366 fast_unload_controller_.reset(new chrome::FastUnloadController(this)); 368 fast_unload_controller_.reset(new chrome::FastUnloadController(this));
367 else 369 else
368 unload_controller_.reset(new chrome::UnloadController(this)); 370 unload_controller_.reset(new chrome::UnloadController(this));
369 371
370 if (!app_name_.empty()) 372 if (!app_name_.empty())
371 chrome::RegisterAppPrefs(app_name_, profile_); 373 chrome::RegisterAppPrefs(app_name_, profile_);
372 tab_strip_model_->AddObserver(this); 374 tab_strip_model_->AddObserver(this);
373 375
374 toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get())); 376 toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get()));
375 search_model_.reset(new SearchModel()); 377 search_model_.reset(new SearchModel());
376 search_delegate_.reset(new SearchDelegate(search_model_.get())); 378 search_delegate_.reset(new SearchDelegate(search_model_.get()));
377 379
378 registrar_.Add(this, 380 extension_registry_observer_.Add(
379 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 381 extensions::ExtensionRegistry::Get(profile_));
380 content::Source<Profile>(profile_->GetOriginalProfile())); 382
381 registrar_.Add(this,
382 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
383 content::Source<Profile>(profile_->GetOriginalProfile()));
384 registrar_.Add(this,
385 extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
386 content::Source<Profile>(profile_->GetOriginalProfile()));
387 registrar_.Add(this, 383 registrar_.Add(this,
388 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 384 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
389 content::NotificationService::AllSources()); 385 content::NotificationService::AllSources());
386
390 #if defined(ENABLE_THEMES) 387 #if defined(ENABLE_THEMES)
391 registrar_.Add( 388 registrar_.Add(
392 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 389 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
393 content::Source<ThemeService>( 390 content::Source<ThemeService>(
394 ThemeServiceFactory::GetForProfile(profile_))); 391 ThemeServiceFactory::GetForProfile(profile_)));
395 #endif 392 #endif
396 registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 393 registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
397 content::NotificationService::AllSources()); 394 content::NotificationService::AllSources());
398 395
399 profile_pref_registrar_.Init(profile_->GetPrefs()); 396 profile_pref_registrar_.Init(profile_->GetPrefs());
(...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 drive::util::MaybeSetDriveURL(profile_, file_info.file_path, &url); 1920 drive::util::MaybeSetDriveURL(profile_, file_info.file_path, &url);
1924 #endif 1921 #endif
1925 1922
1926 if (url.is_empty()) 1923 if (url.is_empty())
1927 return; 1924 return;
1928 1925
1929 OpenURL(OpenURLParams( 1926 OpenURL(OpenURLParams(
1930 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); 1927 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
1931 } 1928 }
1932 1929
1930 // Notification observer for Extension implementation
Bernhard Bauer 2014/09/10 08:03:42 This comment doesn't explain anything that can't b
1931
1932 void Browser::OnExtensionUninstalled(content::BrowserContext* browser_context,
1933 const extensions::Extension* extension,
1934 extensions::UninstallReason reason) {
1935 if (window() && window()->GetLocationBar())
1936 window()->GetLocationBar()->UpdatePageActions();
1937 }
1938
1939 void Browser::OnExtensionLoaded(content::BrowserContext* browser_context,
1940 const extensions::Extension* extension) {
1941 chrome::UpdateCommandEnabled(
1942 this,
1943 IDC_BOOKMARK_PAGE,
1944 !chrome::ShouldRemoveBookmarkThisPageUI(profile_));
1945 chrome::UpdateCommandEnabled(
1946 this,
1947 IDC_BOOKMARK_ALL_TABS,
1948 !chrome::ShouldRemoveBookmarkOpenPagesUI(profile_));
1949 }
1950
1951 void Browser::OnExtensionUnloaded(
1952 content::BrowserContext* browser_context,
1953 const extensions::Extension* extension,
1954 extensions::UnloadedExtensionInfo::Reason reason) {
1955 chrome::UpdateCommandEnabled(
1956 this,
1957 IDC_BOOKMARK_PAGE,
1958 !chrome::ShouldRemoveBookmarkThisPageUI(profile_));
1959 chrome::UpdateCommandEnabled(
1960 this,
1961 IDC_BOOKMARK_ALL_TABS,
1962 !chrome::ShouldRemoveBookmarkOpenPagesUI(profile_));
1963
1964 if (window()->GetLocationBar())
1965 window()->GetLocationBar()->UpdatePageActions();
1966
1967 const extensions::UnloadedExtensionInfo* extension_info =
1968 content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
1969
1970 // Close any tabs from the unloaded extension, unless it's terminated,
1971 // in which case let the sad tabs remain.
1972 if (extension_info->reason !=
1973 extensions::UnloadedExtensionInfo::REASON_TERMINATE) {
1974 const Extension* extension = extension_info->extension;
1975 // Iterate backwards as we may remove items while iterating.
1976 for (int i = tab_strip_model_->count() - 1; i >= 0; --i) {
1977 WebContents* web_contents = tab_strip_model_->GetWebContentsAt(i);
1978 // Two cases are handled here:
1979 // - The scheme check is for when an extension page is loaded in a
1980 // tab, e.g. chrome-extension://id/page.html.
1981 // - The extension_app check is for apps, which can have non-extension
1982 // schemes, e.g. https://mail.google.com if you have the Gmail app
1983 // installed.
1984 if ((web_contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
1985 web_contents->GetURL().host() == extension->id()) ||
1986 (extensions::TabHelper::FromWebContents(web_contents)
1987 ->extension_app() == extension)) {
1988 tab_strip_model_->CloseWebContentsAt(i, TabStripModel::CLOSE_NONE);
1989 }
1990 }
1991 }
1992 }
1933 /////////////////////////////////////////////////////////////////////////////// 1993 ///////////////////////////////////////////////////////////////////////////////
1934 // Browser, content::NotificationObserver implementation: 1994 // Browser, content::NotificationObserver implementation:
1935 1995
1936 void Browser::Observe(int type, 1996 void Browser::Observe(int type,
1937 const content::NotificationSource& source, 1997 const content::NotificationSource& source,
1938 const content::NotificationDetails& details) { 1998 const content::NotificationDetails& details) {
1939 switch (type) { 1999 switch (type) {
1940 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
1941 chrome::UpdateCommandEnabled(
1942 this,
1943 IDC_BOOKMARK_PAGE,
1944 !chrome::ShouldRemoveBookmarkThisPageUI(profile_));
1945 chrome::UpdateCommandEnabled(
1946 this,
1947 IDC_BOOKMARK_ALL_TABS,
1948 !chrome::ShouldRemoveBookmarkOpenPagesUI(profile_));
1949
1950 if (window()->GetLocationBar())
1951 window()->GetLocationBar()->UpdatePageActions();
1952
1953 const extensions::UnloadedExtensionInfo* extension_info =
1954 content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
1955
1956 // Close any tabs from the unloaded extension, unless it's terminated,
1957 // in which case let the sad tabs remain.
1958 if (extension_info->reason !=
1959 extensions::UnloadedExtensionInfo::REASON_TERMINATE) {
1960 const Extension* extension = extension_info->extension;
1961 // Iterate backwards as we may remove items while iterating.
1962 for (int i = tab_strip_model_->count() - 1; i >= 0; --i) {
1963 WebContents* web_contents = tab_strip_model_->GetWebContentsAt(i);
1964 // Two cases are handled here:
1965 // - The scheme check is for when an extension page is loaded in a
1966 // tab, e.g. chrome-extension://id/page.html.
1967 // - The extension_app check is for apps, which can have non-extension
1968 // schemes, e.g. https://mail.google.com if you have the Gmail app
1969 // installed.
1970 if ((web_contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
1971 web_contents->GetURL().host() == extension->id()) ||
1972 (extensions::TabHelper::FromWebContents(
1973 web_contents)->extension_app() == extension)) {
1974 tab_strip_model_->CloseWebContentsAt(i, TabStripModel::CLOSE_NONE);
1975 }
1976 }
1977 }
1978 break;
1979 }
1980
1981 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { 2000 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
1982 Profile* profile = content::Source<Profile>(source).ptr(); 2001 Profile* profile = content::Source<Profile>(source).ptr();
1983 if (profile_->IsSameProfile(profile) && window()->GetLocationBar()) 2002 if (profile_->IsSameProfile(profile) && window()->GetLocationBar())
1984 window()->GetLocationBar()->InvalidatePageActions(); 2003 window()->GetLocationBar()->InvalidatePageActions();
1985 break; 2004 break;
1986 } 2005 }
1987 2006
1988 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED:
1989 chrome::UpdateCommandEnabled(
1990 this,
1991 IDC_BOOKMARK_PAGE,
1992 !chrome::ShouldRemoveBookmarkThisPageUI(profile_));
1993 chrome::UpdateCommandEnabled(
1994 this,
1995 IDC_BOOKMARK_ALL_TABS,
1996 !chrome::ShouldRemoveBookmarkOpenPagesUI(profile_));
1997 // fallthrough
1998 case extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED:
1999 // During window creation on Windows we may end up calling into
2000 // SHAppBarMessage, which internally spawns a nested message loop. This
2001 // makes it possible for us to end up here before window creation has
2002 // completed, at which point window_ is NULL. See 94752 for details.
2003 if (window() && window()->GetLocationBar())
2004 window()->GetLocationBar()->UpdatePageActions();
2005 break;
2006
2007 #if defined(ENABLE_THEMES) 2007 #if defined(ENABLE_THEMES)
2008 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: 2008 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
2009 window()->UserChangedTheme(); 2009 window()->UserChangedTheme();
2010 break; 2010 break;
2011 #endif 2011 #endif
2012 2012
2013 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { 2013 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: {
2014 WebContents* web_contents = content::Source<WebContents>(source).ptr(); 2014 WebContents* web_contents = content::Source<WebContents>(source).ptr();
2015 if (web_contents == tab_strip_model_->GetActiveWebContents()) { 2015 if (web_contents == tab_strip_model_->GetActiveWebContents()) {
2016 LocationBar* location_bar = window()->GetLocationBar(); 2016 LocationBar* location_bar = window()->GetLocationBar();
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
2472 if (contents && !allow_js_access) { 2472 if (contents && !allow_js_access) {
2473 contents->web_contents()->GetController().LoadURL( 2473 contents->web_contents()->GetController().LoadURL(
2474 target_url, 2474 target_url,
2475 content::Referrer(), 2475 content::Referrer(),
2476 content::PAGE_TRANSITION_LINK, 2476 content::PAGE_TRANSITION_LINK,
2477 std::string()); // No extra headers. 2477 std::string()); // No extra headers.
2478 } 2478 }
2479 2479
2480 return contents != NULL; 2480 return contents != NULL;
2481 } 2481 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698