diff options
author | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-22 19:56:14 +0000 |
---|---|---|
committer | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-22 19:56:14 +0000 |
commit | f72298c8e0ce1427e8ed682ca5dad0573d6c2763 (patch) | |
tree | 842b5af9151d68cb51acf5c113d09e43fca703a8 | |
parent | 6d81b488e8cc5e10eaeca0a4ee4819dc3f469a24 (diff) | |
download | chromium_src-f72298c8e0ce1427e8ed682ca5dad0573d6c2763.zip chromium_src-f72298c8e0ce1427e8ed682ca5dad0573d6c2763.tar.gz chromium_src-f72298c8e0ce1427e8ed682ca5dad0573d6c2763.tar.bz2 |
Add an icon to the omnibox when a page is prerendered.
This will only show up for users who have prerendering enabled (mainly via about:flags)
This CL does not include the logic for displaying whether prerender failed on the referring page.
BUG=73065
TEST=Start Chrome with prerendering enabled, go to a page with a <link rel=prefetch> element, navigate to the referred page, and see icon appear.
Review URL: http://codereview.chromium.org/6529031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75621 0039d316-1c4b-4281-b951-d872f2087c98
18 files changed, 152 insertions, 52 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 303ca23..c5c86e4 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -2434,6 +2434,9 @@ each locale. --> <message name="IDS_BLOCKED_PLUGINS_LOAD_ALL" desc="Button to load all blocked plugins on a page, displayed in bubble when a page tries to display plug-ins."> Run all plug-ins this time </message> + <message name="IDS_PRERENDER_SUCCEED_TOOLTIP" desc="Location bar icon tooltip text when the current page is prerendered."> + This page was prerendered. + </message> <!-- Certificate error strings --> <message name="IDS_CERT_ERROR_EXTRA_INFO_TITLE" desc="The title for the extra information section displayed when a page contains a certificate error"> diff --git a/chrome/app/theme/theme_resources.grd b/chrome/app/theme/theme_resources.grd index a50b006..e5a534a 100644 --- a/chrome/app/theme/theme_resources.grd +++ b/chrome/app/theme/theme_resources.grd @@ -270,6 +270,8 @@ <include name="IDR_PAGEINFO_WARNING_MAJOR" file="pageinfo_warning_major.png" type="BINDATA" /> <include name="IDR_PAGEINFO_WARNING_MINOR" file="pageinfo_warning_minor.png" type="BINDATA" /> <include name="IDR_PLUGIN" file="plugin.png" type="BINDATA" /> + <include name="IDR_PRERENDER_FAIL_ICON" file="prerender_fail_icon.png" type="BINDATA"/> + <include name="IDR_PRERENDER_SUCCEED_ICON" file="prerender_succeed_icon.png" type="BINDATA"/> <if expr="pp_ifdef('_google_chrome')"> <include name="IDR_PRODUCT_ICON_32" file="google_chrome/google_chrome_icon_32.png" type="BINDATA" /> <include name="IDR_PRODUCT_LOGO" file="google_chrome/product_logo.png" type="BINDATA" /> diff --git a/chrome/browser/content_setting_bubble_model.cc b/chrome/browser/content_setting_bubble_model.cc index 8a4c6b6..595f1e4 100644 --- a/chrome/browser/content_setting_bubble_model.cc +++ b/chrome/browser/content_setting_bubble_model.cc @@ -58,6 +58,7 @@ class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { IDS_BLOCKED_POPUPS_TITLE, 0, // Geolocation does not have an overall title. 0, // Notifications do not have a bubble. + 0, // Prerender does not have a bubble. }; // Fields as for kBlockedTitleIDs, above. static const int kResourceSpecificBlockedTitleIDs[] = { @@ -68,6 +69,7 @@ class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { 0, 0, 0, + 0, }; static const int kAccessedTitleIDs[] = { IDS_ACCESSED_COOKIES_TITLE, @@ -77,6 +79,7 @@ class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { 0, 0, 0, + 0, }; COMPILE_ASSERT(arraysize(kAccessedTitleIDs) == CONTENT_SETTINGS_NUM_TYPES, Need_a_setting_for_every_content_settings_type); @@ -108,6 +111,7 @@ class ContentSettingTitleAndLinkModel : public ContentSettingBubbleModel { IDS_BLOCKED_POPUPS_LINK, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK, 0, // Notifications do not have a bubble. + 0, // Prerender does not have a bubble. }; COMPILE_ASSERT(arraysize(kLinkIDs) == CONTENT_SETTINGS_NUM_TYPES, Need_a_setting_for_every_content_settings_type); @@ -142,6 +146,7 @@ class ContentSettingTitleLinkAndCustomModel 0, // Popups do not have a custom link. 0, // Geolocation custom links are set within that class. 0, // Notifications do not have a bubble. + 0, // Prerender does not have a bubble. }; COMPILE_ASSERT(arraysize(kCustomIDs) == CONTENT_SETTINGS_NUM_TYPES, Need_a_setting_for_every_content_settings_type); @@ -214,6 +219,7 @@ class ContentSettingSingleRadioGroup IDS_BLOCKED_POPUPS_UNBLOCK, 0, // We don't manage geolocation here. 0, // Notifications do not have a bubble. + 0, // Prerender does not have a bubble. }; COMPILE_ASSERT(arraysize(kAllowIDs) == CONTENT_SETTINGS_NUM_TYPES, Need_a_setting_for_every_content_settings_type); @@ -226,6 +232,7 @@ class ContentSettingSingleRadioGroup 0, 0, 0, + 0, // Prerender does not have a bubble. }; COMPILE_ASSERT( arraysize(kResourceSpecificAllowIDs) == CONTENT_SETTINGS_NUM_TYPES, @@ -244,6 +251,7 @@ class ContentSettingSingleRadioGroup IDS_BLOCKED_POPUPS_NO_ACTION, 0, // We don't manage geolocation here. 0, // Notifications do not have a bubble. + 0, // Prerender does not have a bubble. }; COMPILE_ASSERT(arraysize(kBlockIDs) == CONTENT_SETTINGS_NUM_TYPES, Need_a_setting_for_every_content_settings_type); diff --git a/chrome/browser/content_setting_image_model.cc b/chrome/browser/content_setting_image_model.cc index d533ec2..f20e1eb 100644 --- a/chrome/browser/content_setting_image_model.cc +++ b/chrome/browser/content_setting_image_model.cc @@ -32,14 +32,21 @@ class ContentSettingGeolocationImageModel : public ContentSettingImageModel { public: ContentSettingGeolocationImageModel(); - virtual void UpdateFromTabContents(TabContents* tab_contents); + virtual void UpdateFromTabContents(TabContents* tab_contents) OVERRIDE; }; class ContentSettingNotificationsImageModel : public ContentSettingImageModel { public: ContentSettingNotificationsImageModel(); - virtual void UpdateFromTabContents(TabContents* tab_contents); + virtual void UpdateFromTabContents(TabContents* tab_contents) OVERRIDE; +}; + +class ContentSettingPrerenderImageModel : public ContentSettingImageModel { + public: + ContentSettingPrerenderImageModel(); + + virtual void UpdateFromTabContents(TabContents* tab_contents) OVERRIDE; }; const int ContentSettingBlockedImageModel::kBlockedIconIDs[] = { @@ -164,6 +171,23 @@ void ContentSettingNotificationsImageModel::UpdateFromTabContents( set_visible(false); } +ContentSettingPrerenderImageModel::ContentSettingPrerenderImageModel() + : ContentSettingImageModel(CONTENT_SETTINGS_TYPE_PRERENDER) { + set_tooltip(l10n_util::GetStringUTF8(IDS_PRERENDER_SUCCEED_TOOLTIP)); +} + +void ContentSettingPrerenderImageModel::UpdateFromTabContents( + TabContents* tab_contents) { + bool visible = tab_contents && tab_contents->was_prerendered(); + set_visible(visible); + // ContentSettingPrerenderImageView expects icon to transition from 0 to + // valid each time it wants to be displayed. + if (visible) + set_icon(IDR_PRERENDER_SUCCEED_ICON); + else + set_icon(0); +} + ContentSettingImageModel::ContentSettingImageModel( ContentSettingsType content_settings_type) : content_settings_type_(content_settings_type), @@ -176,9 +200,14 @@ ContentSettingImageModel::ContentSettingImageModel( ContentSettingImageModel* ContentSettingImageModel::CreateContentSettingImageModel( ContentSettingsType content_settings_type) { - if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) - return new ContentSettingGeolocationImageModel(); - if (content_settings_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) - return new ContentSettingNotificationsImageModel(); - return new ContentSettingBlockedImageModel(content_settings_type); + switch (content_settings_type) { + case CONTENT_SETTINGS_TYPE_GEOLOCATION: + return new ContentSettingGeolocationImageModel(); + case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: + return new ContentSettingNotificationsImageModel(); + case CONTENT_SETTINGS_TYPE_PRERENDER: + return new ContentSettingPrerenderImageModel(); + default: + return new ContentSettingBlockedImageModel(content_settings_type); + } } diff --git a/chrome/browser/content_setting_image_model_unittest.cc b/chrome/browser/content_setting_image_model_unittest.cc index fc7989d..07dcba1 100644 --- a/chrome/browser/content_setting_image_model_unittest.cc +++ b/chrome/browser/content_setting_image_model_unittest.cc @@ -34,7 +34,7 @@ TEST_F(ContentSettingImageModelTest, UpdateFromTabContents) { CONTENT_SETTINGS_TYPE_IMAGES)); EXPECT_FALSE(content_setting_image_model->is_visible()); EXPECT_EQ(0, content_setting_image_model->get_icon()); - EXPECT_EQ(std::string(), content_setting_image_model->get_tooltip()); + EXPECT_TRUE(content_setting_image_model->get_tooltip().empty()); content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); @@ -42,7 +42,7 @@ TEST_F(ContentSettingImageModelTest, UpdateFromTabContents) { EXPECT_TRUE(content_setting_image_model->is_visible()); EXPECT_NE(0, content_setting_image_model->get_icon()); - EXPECT_NE(std::string(), content_setting_image_model->get_tooltip()); + EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); } TEST_F(ContentSettingImageModelTest, CookieAccessed) { @@ -56,7 +56,7 @@ TEST_F(ContentSettingImageModelTest, CookieAccessed) { CONTENT_SETTINGS_TYPE_COOKIES)); EXPECT_FALSE(content_setting_image_model->is_visible()); EXPECT_EQ(0, content_setting_image_model->get_icon()); - EXPECT_EQ(std::string(), content_setting_image_model->get_tooltip()); + EXPECT_TRUE(content_setting_image_model->get_tooltip().empty()); net::CookieOptions options; content_settings->OnCookieChanged( @@ -64,5 +64,23 @@ TEST_F(ContentSettingImageModelTest, CookieAccessed) { content_setting_image_model->UpdateFromTabContents(&tab_contents); EXPECT_TRUE(content_setting_image_model->is_visible()); EXPECT_NE(0, content_setting_image_model->get_icon()); - EXPECT_NE(std::string(), content_setting_image_model->get_tooltip()); + EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); } + +TEST_F(ContentSettingImageModelTest, Prerender) { + TestTabContents tab_contents(profile_.get(), NULL); + scoped_ptr<ContentSettingImageModel> content_setting_image_model( + ContentSettingImageModel::CreateContentSettingImageModel( + CONTENT_SETTINGS_TYPE_PRERENDER)); + EXPECT_FALSE(content_setting_image_model->is_visible()); + EXPECT_EQ(0, content_setting_image_model->get_icon()); + EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); + + // Make the tab_contents prerendered + tab_contents.set_was_prerendered(true); + content_setting_image_model->UpdateFromTabContents(&tab_contents); + EXPECT_TRUE(content_setting_image_model->is_visible()); + EXPECT_NE(0, content_setting_image_model->get_icon()); + EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); +} + diff --git a/chrome/browser/content_settings/content_settings_pref_provider.cc b/chrome/browser/content_settings/content_settings_pref_provider.cc index 2365beb..aa739ba 100644 --- a/chrome/browser/content_settings/content_settings_pref_provider.cc +++ b/chrome/browser/content_settings/content_settings_pref_provider.cc @@ -28,7 +28,7 @@ namespace { // The preference keys where resource identifiers are stored for // ContentSettingsType values that support resource identifiers. -const char* kResourceTypeNames[CONTENT_SETTINGS_NUM_TYPES] = { +const char* kResourceTypeNames[] = { NULL, NULL, NULL, @@ -36,10 +36,13 @@ const char* kResourceTypeNames[CONTENT_SETTINGS_NUM_TYPES] = { NULL, NULL, // Not used for Geolocation NULL, // Not used for Notifications + NULL, // Not used for Prerender. }; +COMPILE_ASSERT(arraysize(kResourceTypeNames) == CONTENT_SETTINGS_NUM_TYPES, + resource_type_names_incorrect_size); // The default setting for each content type. -const ContentSetting kDefaultSettings[CONTENT_SETTINGS_NUM_TYPES] = { +const ContentSetting kDefaultSettings[] = { CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT @@ -47,10 +50,13 @@ const ContentSetting kDefaultSettings[CONTENT_SETTINGS_NUM_TYPES] = { CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS CONTENT_SETTING_ASK, // Not used for Geolocation CONTENT_SETTING_ASK, // Not used for Notifications + CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PRERENDER }; +COMPILE_ASSERT(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES, + default_settings_incorrect_size); // The names of the ContentSettingsType values, for use with dictionary prefs. -const char* kTypeNames[CONTENT_SETTINGS_NUM_TYPES] = { +const char* kTypeNames[] = { "cookies", "images", "javascript", @@ -58,7 +64,10 @@ const char* kTypeNames[CONTENT_SETTINGS_NUM_TYPES] = { "popups", NULL, // Not used for Geolocation NULL, // Not used for Notifications + NULL, // Not used for Prerender }; +COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES, + type_names_incorrect_size); } // namespace diff --git a/chrome/browser/content_settings/host_content_settings_map_unittest.cc b/chrome/browser/content_settings/host_content_settings_map_unittest.cc index 7de163d..c2a623f 100644 --- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc +++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc @@ -121,6 +121,8 @@ TEST_F(HostContentSettingsMapTest, DefaultValues) { CONTENT_SETTING_ASK; desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = CONTENT_SETTING_ASK; + desired_settings.settings[CONTENT_SETTINGS_TYPE_PRERENDER] = + CONTENT_SETTING_ALLOW; ContentSettings settings = host_content_settings_map->GetContentSettings(host); EXPECT_TRUE(SettingsEqual(desired_settings, settings)); @@ -422,6 +424,8 @@ TEST_F(HostContentSettingsMapTest, NestedSettings) { CONTENT_SETTING_ASK; desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = CONTENT_SETTING_ASK; + desired_settings.settings[CONTENT_SETTINGS_TYPE_PRERENDER] = + CONTENT_SETTING_ALLOW; ContentSettings settings = host_content_settings_map->GetContentSettings(host); EXPECT_TRUE(SettingsEqual(desired_settings, settings)); diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc index 992c325..5a64cf6 100644 --- a/chrome/browser/prerender/prerender_manager.cc +++ b/chrome/browser/prerender/prerender_manager.cc @@ -159,6 +159,8 @@ bool PrerenderManager::MaybeUsePreloadedPage(TabContents* tc, const GURL& url) { if (pc->has_stopped_loading()) tc->DidStopLoading(); + tc->set_was_prerendered(true); + return true; } diff --git a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm index 08970b8..cbecce9 100644 --- a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm +++ b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm @@ -129,6 +129,7 @@ NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) { @"ContentBlockedPopups", @"ContentBubbleGeolocation", @"", // Notifications do not have a bubble. + @"", // Prerender does not have a bubble. }; COMPILE_ASSERT(arraysize(nibPaths) == CONTENT_SETTINGS_NUM_TYPES, nibPaths_requires_an_entry_for_every_setting_type); diff --git a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm index 88d485b..9f38322 100644 --- a/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm +++ b/chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm @@ -34,6 +34,8 @@ TEST_F(ContentSettingBubbleControllerTest, Init) { for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { if (i == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) continue; // Notifications have no bubble. + if (i == CONTENT_SETTINGS_TYPE_PRERENDER) + continue; // Prerender has no bubble. ContentSettingsType settingsType = static_cast<ContentSettingsType>(i); diff --git a/chrome/browser/ui/cocoa/location_bar/content_setting_decoration.mm b/chrome/browser/ui/cocoa/location_bar/content_setting_decoration.mm index 61d4d38..bd58249 100644 --- a/chrome/browser/ui/cocoa/location_bar/content_setting_decoration.mm +++ b/chrome/browser/ui/cocoa/location_bar/content_setting_decoration.mm @@ -249,6 +249,12 @@ bool ContentSettingDecoration::OnMousePressed(NSRect frame) { if (!tabContents) return true; + // Prerender icon does not include a bubble. + ContentSettingsType content_settings_type = + content_setting_image_model_->get_content_settings_type(); + if (content_settings_type == CONTENT_SETTINGS_TYPE_PRERENDER) + return true; + GURL url = tabContents->GetURL(); std::wstring displayHost; net::AppendFormattedHost( @@ -269,8 +275,7 @@ bool ContentSettingDecoration::OnMousePressed(NSRect frame) { // Open bubble. ContentSettingBubbleModel* model = ContentSettingBubbleModel::CreateContentSettingBubbleModel( - tabContents, profile_, - content_setting_image_model_->get_content_settings_type()); + tabContents, profile_, content_settings_type); [ContentSettingBubbleController showForModel:model parentWindow:[field window] anchoredAt:anchor]; diff --git a/chrome/browser/ui/gtk/options/content_filter_page_gtk.cc b/chrome/browser/ui/gtk/options/content_filter_page_gtk.cc index 4d60dcd3..309d7c9a 100644 --- a/chrome/browser/ui/gtk/options/content_filter_page_gtk.cc +++ b/chrome/browser/ui/gtk/options/content_filter_page_gtk.cc @@ -43,6 +43,7 @@ ContentFilterPageGtk::ContentFilterPageGtk(Profile* profile, IDS_POPUP_SETTING_LABEL, IDS_GEOLOCATION_SETTING_LABEL, IDS_NOTIFICATIONS_SETTING_LABEL, + 0, // This dialog isn't used for prerender. }; COMPILE_ASSERT(arraysize(kTitleIDs) == CONTENT_SETTINGS_NUM_TYPES, kTitleIDs_IncorrectSize); @@ -69,6 +70,7 @@ GtkWidget* ContentFilterPageGtk::InitGroup() { IDS_POPUP_ALLOW_RADIO, IDS_GEOLOCATION_ALLOW_RADIO, IDS_NOTIFICATIONS_ALLOW_RADIO, + 0, // This dialog isn't used for prerender. }; COMPILE_ASSERT(arraysize(kAllowIDs) == CONTENT_SETTINGS_NUM_TYPES, kAllowIDs_IncorrectSize); @@ -84,6 +86,7 @@ GtkWidget* ContentFilterPageGtk::InitGroup() { 0, IDS_GEOLOCATION_ASK_RADIO, IDS_NOTIFICATIONS_ASK_RADIO, + 0, // This dialog isn't used for prerender. }; COMPILE_ASSERT(arraysize(kAskIDs) == CONTENT_SETTINGS_NUM_TYPES, kAskIDs_IncorrectSize); @@ -109,6 +112,7 @@ GtkWidget* ContentFilterPageGtk::InitGroup() { IDS_POPUP_BLOCK_RADIO, IDS_GEOLOCATION_BLOCK_RADIO, IDS_NOTIFICATIONS_BLOCK_RADIO, + 0, // This dialog isn't used for prerender. }; COMPILE_ASSERT(arraysize(kBlockIDs) == CONTENT_SETTINGS_NUM_TYPES, kBlockIDs_IncorrectSize); diff --git a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc index 66ddcda..6237c4a 100644 --- a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc +++ b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc @@ -136,6 +136,12 @@ void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event, if (!tab_contents) return; + // Prerender does not have a bubble. + ContentSettingsType content_settings_type = + content_setting_image_model_->get_content_settings_type(); + if (content_settings_type == CONTENT_SETTINGS_TYPE_PRERENDER) + return; + gfx::Rect screen_bounds(GetImageBounds()); gfx::Point origin(screen_bounds.origin()); views::View::ConvertPointToScreen(this, &origin); @@ -143,8 +149,7 @@ void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event, ContentSettingBubbleContents* bubble_contents = new ContentSettingBubbleContents( ContentSettingBubbleModel::CreateContentSettingBubbleModel( - tab_contents, profile_, - content_setting_image_model_->get_content_settings_type()), + tab_contents, profile_, content_settings_type), profile_, tab_contents); info_bubble_ = InfoBubble::Show(GetWidget(), screen_bounds, BubbleBorder::TOP_RIGHT, bubble_contents, this); diff --git a/chrome/browser/ui/views/options/content_filter_page_view.cc b/chrome/browser/ui/views/options/content_filter_page_view.cc index 265bd63..1e4170b 100644 --- a/chrome/browser/ui/views/options/content_filter_page_view.cc +++ b/chrome/browser/ui/views/options/content_filter_page_view.cc @@ -63,6 +63,7 @@ void ContentFilterPageView::InitControlLayout() { IDS_POPUP_SETTING_LABEL, IDS_GEOLOCATION_SETTING_LABEL, IDS_NOTIFICATIONS_SETTING_LABEL, + 0, }; COMPILE_ASSERT(arraysize(kTitleIDs) == CONTENT_SETTINGS_NUM_TYPES, Need_a_setting_for_every_content_settings_type); @@ -83,6 +84,7 @@ void ContentFilterPageView::InitControlLayout() { IDS_POPUP_ALLOW_RADIO, IDS_GEOLOCATION_ALLOW_RADIO, IDS_NOTIFICATIONS_ALLOW_RADIO, + 0, }; COMPILE_ASSERT(arraysize(kAllowIDs) == CONTENT_SETTINGS_NUM_TYPES, Need_a_setting_for_every_content_settings_type); @@ -104,6 +106,7 @@ void ContentFilterPageView::InitControlLayout() { 0, IDS_GEOLOCATION_ASK_RADIO, IDS_NOTIFICATIONS_ASK_RADIO, + 0, }; COMPILE_ASSERT(arraysize(kAskIDs) == CONTENT_SETTINGS_NUM_TYPES, Need_a_setting_for_every_content_settings_type); @@ -133,6 +136,7 @@ void ContentFilterPageView::InitControlLayout() { IDS_POPUP_BLOCK_RADIO, IDS_GEOLOCATION_BLOCK_RADIO, IDS_NOTIFICATIONS_BLOCK_RADIO, + 0, }; COMPILE_ASSERT(arraysize(kBlockIDs) == CONTENT_SETTINGS_NUM_TYPES, Need_a_setting_for_every_content_settings_type); diff --git a/chrome/browser/webui/options/content_settings_handler.cc b/chrome/browser/webui/options/content_settings_handler.cc index 88e7c3a..9be48e1 100644 --- a/chrome/browser/webui/options/content_settings_handler.cc +++ b/chrome/browser/webui/options/content_settings_handler.cc @@ -33,21 +33,29 @@ const char* kSetting = "setting"; const char* kOrigin = "origin"; const char* kEmbeddingOrigin = "embeddingOrigin"; +const char* const kContentSettingsTypeGroupNames[] = { + "cookies", + "images", + "javascript", + "plugins", + "popups", + "location", + "notifications", + "prerender", +}; +COMPILE_ASSERT(arraysize(kContentSettingsTypeGroupNames) == + CONTENT_SETTINGS_NUM_TYPES, + invalid_content_settings_type_group_names_size); + + ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { - if (name == "cookies") - return CONTENT_SETTINGS_TYPE_COOKIES; - if (name == "images") - return CONTENT_SETTINGS_TYPE_IMAGES; - if (name == "javascript") - return CONTENT_SETTINGS_TYPE_JAVASCRIPT; - if (name == "plugins") - return CONTENT_SETTINGS_TYPE_PLUGINS; - if (name == "popups") - return CONTENT_SETTINGS_TYPE_POPUPS; - if (name == "location") - return CONTENT_SETTINGS_TYPE_GEOLOCATION; - if (name == "notifications") - return CONTENT_SETTINGS_TYPE_NOTIFICATIONS; + + for (int content_settings_type = CONTENT_SETTINGS_TYPE_COOKIES; + content_settings_type < CONTENT_SETTINGS_NUM_TYPES; + ++content_settings_type) { + if (name == kContentSettingsTypeGroupNames[content_settings_type]) + return static_cast<ContentSettingsType>(content_settings_type); + } NOTREACHED() << name << " is not a recognized content settings type."; return CONTENT_SETTINGS_TYPE_DEFAULT; @@ -693,26 +701,12 @@ void ContentSettingsHandler::CheckExceptionPatternValidity( // static std::string ContentSettingsHandler::ContentSettingsTypeToGroupName( ContentSettingsType type) { - switch (type) { - case CONTENT_SETTINGS_TYPE_COOKIES: - return "cookies"; - case CONTENT_SETTINGS_TYPE_IMAGES: - return "images"; - case CONTENT_SETTINGS_TYPE_JAVASCRIPT: - return "javascript"; - case CONTENT_SETTINGS_TYPE_PLUGINS: - return "plugins"; - case CONTENT_SETTINGS_TYPE_POPUPS: - return "popups"; - case CONTENT_SETTINGS_TYPE_GEOLOCATION: - return "location"; - case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: - return "notifications"; - - default: - NOTREACHED(); - return ""; + if (type < CONTENT_SETTINGS_TYPE_COOKIES || + type >= CONTENT_SETTINGS_NUM_TYPES) { + NOTREACHED(); + return ""; } + return kContentSettingsTypeGroupNames[type]; } HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { diff --git a/chrome/common/content_settings_types.h b/chrome/common/content_settings_types.h index 938adbf..a19b798 100644 --- a/chrome/common/content_settings_types.h +++ b/chrome/common/content_settings_types.h @@ -19,6 +19,7 @@ enum ContentSettingsType { CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, + CONTENT_SETTINGS_TYPE_PRERENDER, CONTENT_SETTINGS_NUM_TYPES }; diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 30b91e9..7f8814c 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -279,7 +279,8 @@ TabContents::TabContents(Profile* profile, maximum_zoom_percent_( static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), temporary_zoom_settings_(false), - content_restrictions_(0) { + content_restrictions_(0), + was_prerendered_(false) { renderer_preferences_util::UpdateFromSystemSettings( &renderer_preferences_, profile); @@ -1376,6 +1377,8 @@ void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id, if (!is_error_page) content_settings_delegate_->ClearCookieSpecificContentSettings(); content_settings_delegate_->ClearGeolocationContentSettings(); + // TODO(cbentzel): Should error pages still show prerendered icon? + set_was_prerendered(false); // Check if the URL we are about to load has been prerendered by any chance, // and use it if possible. diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index 318e9fc..a419434 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -715,6 +715,9 @@ class TabContents : public PageNavigator, return safebrowsing_detection_host_.get(); } + bool was_prerendered() const { return was_prerendered_; } + void set_was_prerendered(bool prerendered) { was_prerendered_ = prerendered; } + protected: // from RenderViewHostDelegate. virtual bool OnMessageReceived(const IPC::Message& message); @@ -1252,6 +1255,9 @@ class TabContents : public PageNavigator, // (full-page plugins for now only) permissions. int content_restrictions_; + // Were the contents of this tab previously prerendered? + bool was_prerendered_; + DISALLOW_COPY_AND_ASSIGN(TabContents); }; |