Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 #include "net/cookies/cookie_monster.h" | 187 #include "net/cookies/cookie_monster.h" |
| 188 #include "net/url_request/url_request_context.h" | 188 #include "net/url_request/url_request_context.h" |
| 189 #include "ui/base/animation/animation.h" | 189 #include "ui/base/animation/animation.h" |
| 190 #include "ui/base/dialogs/selected_file_info.h" | 190 #include "ui/base/dialogs/selected_file_info.h" |
| 191 #include "ui/base/l10n/l10n_util.h" | 191 #include "ui/base/l10n/l10n_util.h" |
| 192 #include "ui/gfx/point.h" | 192 #include "ui/gfx/point.h" |
| 193 #include "webkit/glue/web_intent_data.h" | 193 #include "webkit/glue/web_intent_data.h" |
| 194 #include "webkit/glue/web_intent_service_data.h" | 194 #include "webkit/glue/web_intent_service_data.h" |
| 195 #include "webkit/glue/webkit_glue.h" | 195 #include "webkit/glue/webkit_glue.h" |
| 196 #include "webkit/glue/window_open_disposition.h" | 196 #include "webkit/glue/window_open_disposition.h" |
| 197 #include "webkit/plugins/npapi/plugin_group.h" | |
| 198 #include "webkit/plugins/npapi/plugin_list.h" | |
| 197 #include "webkit/plugins/webplugininfo.h" | 199 #include "webkit/plugins/webplugininfo.h" |
| 198 | 200 |
| 199 #if defined(OS_WIN) | 201 #if defined(OS_WIN) |
| 200 #include "base/win/metro.h" | 202 #include "base/win/metro.h" |
| 201 #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" | 203 #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" |
| 202 #include "chrome/browser/shell_integration.h" | 204 #include "chrome/browser/shell_integration.h" |
| 203 #include "chrome/browser/ssl/ssl_error_info.h" | 205 #include "chrome/browser/ssl/ssl_error_info.h" |
| 204 #include "chrome/browser/task_manager/task_manager.h" | 206 #include "chrome/browser/task_manager/task_manager.h" |
| 205 #include "chrome/browser/ui/view_ids.h" | 207 #include "chrome/browser/ui/view_ids.h" |
| 206 #include "ui/base/win/shell.h" | 208 #include "ui/base/win/shell.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 232 namespace { | 234 namespace { |
| 233 | 235 |
| 234 // The URL to be loaded to display the "Report a broken page" form. | 236 // The URL to be loaded to display the "Report a broken page" form. |
| 235 const char kBrokenPageUrl[] = | 237 const char kBrokenPageUrl[] = |
| 236 "https://www.google.com/support/chrome/bin/request.py?contact_type=" | 238 "https://www.google.com/support/chrome/bin/request.py?contact_type=" |
| 237 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; | 239 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; |
| 238 | 240 |
| 239 // The URL for the privacy dashboard. | 241 // The URL for the privacy dashboard. |
| 240 const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; | 242 const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; |
| 241 | 243 |
| 244 // The URL for the "learn more" article about the PPAPI broker. | |
| 245 const char kPpapiBrokerLearnMoreUrl[] = | |
| 246 "https://support.google.com/chrome/?p=ib_pepper_broker"; | |
| 247 | |
| 242 // How long we wait before updating the browser chrome while loading a page. | 248 // How long we wait before updating the browser chrome while loading a page. |
| 243 const int kUIUpdateCoalescingTimeMS = 200; | 249 const int kUIUpdateCoalescingTimeMS = 200; |
| 244 | 250 |
| 245 bool AllowPanels(const std::string& app_name) { | 251 bool AllowPanels(const std::string& app_name) { |
| 246 return PanelManager::ShouldUsePanels( | 252 return PanelManager::ShouldUsePanels( |
| 247 web_app::GetExtensionIdFromApplicationName(app_name)); | 253 web_app::GetExtensionIdFromApplicationName(app_name)); |
| 248 } | 254 } |
| 249 | 255 |
| 250 BrowserWindow* CreateBrowserWindow(Browser* browser) { | 256 BrowserWindow* CreateBrowserWindow(Browser* browser) { |
| 251 #if !defined(USE_ASH) | 257 #if !defined(USE_ASH) |
| 252 if (browser->is_type_panel()) | 258 if (browser->is_type_panel()) |
| 253 return PanelManager::GetInstance()->CreatePanel(browser)->browser_window(); | 259 return PanelManager::GetInstance()->CreatePanel(browser)->browser_window(); |
| 254 #endif | 260 #endif |
| 255 return BrowserWindow::CreateBrowserWindow(browser); | 261 return BrowserWindow::CreateBrowserWindow(browser); |
| 256 } | 262 } |
| 257 | 263 |
| 264 class PpapiBrokerPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { | |
|
markusheintz_
2012/08/13 06:09:06
nit: I wonder whether this class should live in it
Bernhard Bauer
2012/08/13 10:51:46
Yeah, I'm not sure either. I'm slightly leaning to
| |
| 265 public: | |
| 266 PpapiBrokerPermissionInfoBarDelegate( | |
| 267 InfoBarTabHelper* helper, | |
| 268 const GURL& url, | |
| 269 const FilePath& plugin_path, | |
| 270 const std::string& languages, | |
| 271 HostContentSettingsMap* content_settings, | |
| 272 const base::Callback<void(bool)>& callback); | |
| 273 ~PpapiBrokerPermissionInfoBarDelegate(); | |
| 274 | |
| 275 // ConfirmInfoBarDelegate: | |
| 276 virtual string16 GetMessageText() const OVERRIDE; | |
| 277 virtual int GetButtons() const OVERRIDE; | |
| 278 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | |
| 279 virtual bool Accept() OVERRIDE; | |
| 280 virtual bool Cancel() OVERRIDE; | |
| 281 virtual string16 GetLinkText() const OVERRIDE; | |
| 282 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; | |
| 283 virtual gfx::Image* GetIcon() const OVERRIDE; | |
| 284 | |
| 285 private: | |
| 286 GURL url_; | |
| 287 FilePath plugin_path_; | |
| 288 std::string languages_; | |
| 289 HostContentSettingsMap* content_settings_; | |
| 290 base::Callback<void(bool)> callback_; | |
| 291 }; | |
| 292 | |
| 293 PpapiBrokerPermissionInfoBarDelegate::PpapiBrokerPermissionInfoBarDelegate( | |
| 294 InfoBarTabHelper* helper, | |
| 295 const GURL& url, | |
| 296 const FilePath& plugin_path, | |
| 297 const std::string& languages, | |
| 298 HostContentSettingsMap* content_settings, | |
| 299 const base::Callback<void(bool)>& callback) | |
| 300 : ConfirmInfoBarDelegate(helper), | |
| 301 url_(url), | |
| 302 plugin_path_(plugin_path), | |
| 303 languages_(languages), | |
| 304 content_settings_(content_settings), | |
| 305 callback_(callback) { | |
| 306 } | |
| 307 | |
| 308 PpapiBrokerPermissionInfoBarDelegate::~PpapiBrokerPermissionInfoBarDelegate() { | |
| 309 if (!callback_.is_null()) | |
| 310 callback_.Run(false); | |
| 311 } | |
| 312 | |
| 313 string16 PpapiBrokerPermissionInfoBarDelegate::GetMessageText() const { | |
| 314 content::PluginService* plugin_service = | |
| 315 content::PluginService::GetInstance(); | |
| 316 webkit::WebPluginInfo plugin; | |
| 317 bool success = plugin_service->GetPluginInfoByPath(plugin_path_, &plugin); | |
| 318 DCHECK(success); | |
| 319 scoped_ptr<webkit::npapi::PluginGroup> plugin_group( | |
| 320 plugin_service->GetPluginList()->GetPluginGroup(plugin)); | |
| 321 return l10n_util::GetStringFUTF16(IDS_PPAPI_BROKER_INFOBAR_QUESTION, | |
| 322 plugin_group->GetGroupName(), | |
| 323 net::FormatUrl(url_, languages_)); | |
| 324 } | |
| 325 | |
| 326 int PpapiBrokerPermissionInfoBarDelegate::GetButtons() const { | |
| 327 return BUTTON_OK | BUTTON_CANCEL; | |
| 328 } | |
| 329 | |
| 330 string16 PpapiBrokerPermissionInfoBarDelegate::GetButtonLabel( | |
| 331 InfoBarButton button) const { | |
| 332 switch (button) { | |
| 333 case BUTTON_OK: | |
| 334 return l10n_util::GetStringUTF16(IDS_PPAPI_BROKER_ALLOW_BUTTON); | |
| 335 case BUTTON_CANCEL: | |
| 336 return l10n_util::GetStringUTF16(IDS_PPAPI_BROKER_DENY_BUTTON); | |
| 337 default: | |
| 338 NOTREACHED(); | |
| 339 return string16(); | |
| 340 } | |
| 341 } | |
| 342 | |
| 343 bool PpapiBrokerPermissionInfoBarDelegate::Accept() { | |
| 344 callback_.Run(true); | |
| 345 callback_ = base::Callback<void(bool)>(); | |
| 346 content_settings_->SetContentSetting( | |
| 347 ContentSettingsPattern::FromURLNoWildcard(url_), | |
| 348 ContentSettingsPattern::Wildcard(), | |
| 349 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | |
| 350 std::string(), CONTENT_SETTING_ALLOW); | |
| 351 return true; | |
| 352 } | |
| 353 | |
| 354 bool PpapiBrokerPermissionInfoBarDelegate::Cancel() { | |
| 355 callback_.Run(false); | |
| 356 callback_ = base::Callback<void(bool)>(); | |
| 357 return true; | |
| 358 } | |
| 359 | |
| 360 string16 PpapiBrokerPermissionInfoBarDelegate::GetLinkText() const { | |
| 361 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | |
| 362 } | |
| 363 | |
| 364 bool PpapiBrokerPermissionInfoBarDelegate::LinkClicked( | |
| 365 WindowOpenDisposition disposition) { | |
| 366 OpenURLParams params( | |
| 367 GURL(kPpapiBrokerLearnMoreUrl), Referrer(), | |
| 368 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | |
| 369 content::PAGE_TRANSITION_LINK, | |
| 370 false); | |
| 371 owner()->web_contents()->OpenURL(params); | |
| 372 return false; | |
| 373 } | |
| 374 | |
| 375 gfx::Image* PpapiBrokerPermissionInfoBarDelegate::GetIcon() const { | |
| 376 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
| 377 IDR_INFOBAR_PLUGIN_INSTALL); | |
| 378 } | |
| 379 | |
| 258 } // namespace | 380 } // namespace |
| 259 | 381 |
| 260 //////////////////////////////////////////////////////////////////////////////// | 382 //////////////////////////////////////////////////////////////////////////////// |
| 261 // Browser, CreateParams: | 383 // Browser, CreateParams: |
| 262 | 384 |
| 263 Browser::CreateParams::CreateParams() | 385 Browser::CreateParams::CreateParams() |
| 264 : type(TYPE_TABBED), | 386 : type(TYPE_TABBED), |
| 265 profile(NULL), | 387 profile(NULL), |
| 266 app_type(APP_TYPE_HOST), | 388 app_type(APP_TYPE_HOST), |
| 267 initial_show_state(ui::SHOW_STATE_DEFAULT), | 389 initial_show_state(ui::SHOW_STATE_DEFAULT), |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 954 infobar_helper->AddInfoBar(infobar); | 1076 infobar_helper->AddInfoBar(infobar); |
| 955 } | 1077 } |
| 956 } | 1078 } |
| 957 | 1079 |
| 958 // static | 1080 // static |
| 959 void Browser::RequestPpapiBrokerPermissionHelper( | 1081 void Browser::RequestPpapiBrokerPermissionHelper( |
| 960 WebContents* web_contents, | 1082 WebContents* web_contents, |
| 961 const GURL& url, | 1083 const GURL& url, |
| 962 const FilePath& plugin_path, | 1084 const FilePath& plugin_path, |
| 963 const base::Callback<void(bool)>& callback) { | 1085 const base::Callback<void(bool)>& callback) { |
| 964 // TODO(bauerb): Request permission. | 1086 TabContents* tab = TabContents::FromWebContents(web_contents); |
| 965 callback.Run(true); | 1087 if (!tab) { |
| 1088 callback.Run(false); | |
| 1089 return; | |
| 1090 } | |
| 1091 | |
| 1092 Profile* profile = tab->profile(); | |
| 1093 HostContentSettingsMap* content_settings = | |
| 1094 profile->GetHostContentSettingsMap(); | |
| 1095 ContentSetting setting = | |
| 1096 content_settings->GetContentSetting(url, url, | |
| 1097 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | |
| 1098 std::string()); | |
| 1099 switch (setting) { | |
| 1100 case CONTENT_SETTING_ALLOW: { | |
| 1101 callback.Run(true); | |
| 1102 break; | |
| 1103 } | |
| 1104 case CONTENT_SETTING_BLOCK: { | |
| 1105 callback.Run(false); | |
| 1106 break; | |
| 1107 } | |
| 1108 case CONTENT_SETTING_ASK: { | |
| 1109 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); | |
| 1110 std::string languages = | |
| 1111 profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | |
| 1112 infobar_helper->AddInfoBar( | |
| 1113 new PpapiBrokerPermissionInfoBarDelegate( | |
| 1114 infobar_helper, url, plugin_path, languages, content_settings, | |
| 1115 callback)); | |
| 1116 break; | |
| 1117 } | |
| 1118 default: | |
| 1119 NOTREACHED(); | |
| 1120 } | |
| 966 } | 1121 } |
| 967 | 1122 |
| 968 void Browser::UpdateUIForNavigationInTab(TabContents* contents, | 1123 void Browser::UpdateUIForNavigationInTab(TabContents* contents, |
| 969 content::PageTransition transition, | 1124 content::PageTransition transition, |
| 970 bool user_initiated) { | 1125 bool user_initiated) { |
| 971 tab_strip_model_->TabNavigating(contents, transition); | 1126 tab_strip_model_->TabNavigating(contents, transition); |
| 972 | 1127 |
| 973 bool contents_is_selected = contents == chrome::GetActiveTabContents(this); | 1128 bool contents_is_selected = contents == chrome::GetActiveTabContents(this); |
| 974 if (user_initiated && contents_is_selected && window()->GetLocationBar()) { | 1129 if (user_initiated && contents_is_selected && window()->GetLocationBar()) { |
| 975 // Forcibly reset the location bar if the url is going to change in the | 1130 // Forcibly reset the location bar if the url is going to change in the |
| (...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2314 if (contents && !allow_js_access) { | 2469 if (contents && !allow_js_access) { |
| 2315 contents->web_contents()->GetController().LoadURL( | 2470 contents->web_contents()->GetController().LoadURL( |
| 2316 target_url, | 2471 target_url, |
| 2317 content::Referrer(), | 2472 content::Referrer(), |
| 2318 content::PAGE_TRANSITION_LINK, | 2473 content::PAGE_TRANSITION_LINK, |
| 2319 std::string()); // No extra headers. | 2474 std::string()); // No extra headers. |
| 2320 } | 2475 } |
| 2321 | 2476 |
| 2322 return contents != NULL; | 2477 return contents != NULL; |
| 2323 } | 2478 } |
| OLD | NEW |