Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/app_list/start_page_service.h" | 5 #include "chrome/browser/ui/app_list/start_page_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/metrics/user_metrics.h" | 12 #include "base/metrics/user_metrics.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/media/media_stream_infobar_delegate.h" | 16 #include "chrome/browser/media/media_stream_infobar_delegate.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/search/hotword_service.h" | 18 #include "chrome/browser/search/hotword_service.h" |
| 19 #include "chrome/browser/search/hotword_service_factory.h" | 19 #include "chrome/browser/search/hotword_service_factory.h" |
| 20 #include "chrome/browser/ui/app_list/recommended_apps.h" | 20 #include "chrome/browser/ui/app_list/recommended_apps.h" |
| 21 #include "chrome/browser/ui/app_list/speech_auth_helper.h" | 21 #include "chrome/browser/ui/app_list/speech_auth_helper.h" |
| 22 #include "chrome/browser/ui/app_list/speech_recognizer.h" | 22 #include "chrome/browser/ui/app_list/speech_recognizer.h" |
| 23 #include "chrome/browser/ui/app_list/start_page_observer.h" | 23 #include "chrome/browser/ui/app_list/start_page_observer.h" |
| 24 #include "chrome/browser/ui/app_list/start_page_service_factory.h" | 24 #include "chrome/browser/ui/app_list/start_page_service_factory.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "components/ui/zoom/zoom_controller.h" | |
| 28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/notification_details.h" | 30 #include "content/public/browser/notification_details.h" |
| 30 #include "content/public/browser/notification_observer.h" | 31 #include "content/public/browser/notification_observer.h" |
| 31 #include "content/public/browser/notification_registrar.h" | 32 #include "content/public/browser/notification_registrar.h" |
| 32 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/notification_source.h" | 34 #include "content/public/browser/notification_source.h" |
| 34 #include "content/public/browser/speech_recognition_session_preamble.h" | 35 #include "content/public/browser/speech_recognition_session_preamble.h" |
| 35 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/browser/web_contents_delegate.h" | 37 #include "content/public/browser/web_contents_delegate.h" |
| 37 #include "extensions/browser/extension_system_provider.h" | 38 #include "extensions/browser/extension_system_provider.h" |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 void StartPageService::Shutdown() { | 441 void StartPageService::Shutdown() { |
| 441 UnloadContents(); | 442 UnloadContents(); |
| 442 #if defined(OS_CHROMEOS) | 443 #if defined(OS_CHROMEOS) |
| 443 audio_status_.reset(); | 444 audio_status_.reset(); |
| 444 #endif | 445 #endif |
| 445 | 446 |
| 446 speech_auth_helper_.reset(); | 447 speech_auth_helper_.reset(); |
| 447 network_change_observer_.reset(); | 448 network_change_observer_.reset(); |
| 448 } | 449 } |
| 449 | 450 |
| 451 // Set the zoom level in DidNavigateMainFrame, as this is the earliest point | |
| 452 // at which it can be done and not be affected by the ZoomController's | |
| 453 // DidNavigateMainFrame handler. | |
|
Matt Giuca
2015/01/20 07:15:01
Weird place for a comment (don't usually document
benwells
2015/01/20 07:31:09
Done.
| |
| 454 void StartPageService::DidNavigateMainFrame( | |
| 455 const content::LoadCommittedDetails& /* details */, | |
| 456 const content::FrameNavigateParams& /* params */ ) { | |
|
Matt Giuca
2015/01/20 07:15:01
Nit: No spaces in between the /* and */ (see style
benwells
2015/01/20 07:31:09
Done.
| |
| 457 // Use a temporary zoom level for this web contents (aka isolated zoom | |
| 458 // mode) so changes to its zoom aren't reflected in any preferences. | |
| 459 ui_zoom::ZoomController::FromWebContents(contents_.get())->SetZoomMode( | |
| 460 ui_zoom::ZoomController::ZOOM_MODE_ISOLATED); | |
| 461 // Set to have a zoom level of '0', which corresponds to 100%, so the | |
|
Matt Giuca
2015/01/20 07:15:01
Nit: Remove quotes around '0' (it is a number, not
benwells
2015/01/20 07:31:09
Done.
| |
| 462 // contents aren't affected by the browser's default zoom level. | |
| 463 ui_zoom::ZoomController::FromWebContents(contents_.get())->SetZoomLevel(0); | |
| 464 } | |
| 465 | |
| 450 void StartPageService::WebUILoaded() { | 466 void StartPageService::WebUILoaded() { |
| 451 // There's a race condition between the WebUI loading, and calling its JS | 467 // There's a race condition between the WebUI loading, and calling its JS |
| 452 // functions. Specifically, calling LoadContents() doesn't mean that the page | 468 // functions. Specifically, calling LoadContents() doesn't mean that the page |
| 453 // has loaded, but several code paths make this assumption. This function | 469 // has loaded, but several code paths make this assumption. This function |
| 454 // allows us to defer calling JS functions until after the page has finished | 470 // allows us to defer calling JS functions until after the page has finished |
| 455 // loading. | 471 // loading. |
| 456 webui_finished_loading_ = true; | 472 webui_finished_loading_ = true; |
| 457 for (const auto& cb : pending_webui_callbacks_) | 473 for (const auto& cb : pending_webui_callbacks_) |
| 458 cb.Run(); | 474 cb.Run(); |
| 459 pending_webui_callbacks_.clear(); | 475 pending_webui_callbacks_.clear(); |
| 460 } | 476 } |
| 461 | 477 |
| 462 void StartPageService::LoadContents() { | 478 void StartPageService::LoadContents() { |
| 463 contents_.reset(content::WebContents::Create( | 479 contents_.reset(content::WebContents::Create( |
| 464 content::WebContents::CreateParams(profile_))); | 480 content::WebContents::CreateParams(profile_))); |
| 465 contents_delegate_.reset(new StartPageWebContentsDelegate()); | 481 contents_delegate_.reset(new StartPageWebContentsDelegate()); |
| 466 contents_->SetDelegate(contents_delegate_.get()); | 482 contents_->SetDelegate(contents_delegate_.get()); |
| 467 | 483 |
| 484 // The ZoomController needs to be created before the web contents is observed | |
| 485 // by this object. Otherwise it will react to DidNavigateMainFrame after this | |
| 486 // object does, resetting the zoom mode in the process. | |
| 487 ui_zoom::ZoomController::CreateForWebContents(contents_.get()); | |
| 488 Observe(contents_.get()); | |
| 489 | |
| 468 contents_->GetController().LoadURL( | 490 contents_->GetController().LoadURL( |
| 469 GURL(chrome::kChromeUIAppListStartPageURL), | 491 GURL(chrome::kChromeUIAppListStartPageURL), |
| 470 content::Referrer(), | 492 content::Referrer(), |
| 471 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 493 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 472 std::string()); | 494 std::string()); |
| 473 } | 495 } |
| 474 | 496 |
| 475 void StartPageService::UnloadContents() { | 497 void StartPageService::UnloadContents() { |
| 476 contents_.reset(); | 498 contents_.reset(); |
|
Matt Giuca
2015/01/20 07:15:01
I think you need to add:
Observe(nullptr);
BEFORE
benwells
2015/01/20 07:31:09
I don't think it's needed. See https://code.google
Matt Giuca
2015/01/20 22:39:23
That removes the pointers from the WebContents to
Matt Giuca
2015/01/21 00:08:38
Oops, as discussed offline, the WebContents destru
| |
| 477 webui_finished_loading_ = false; | 499 webui_finished_loading_ = false; |
| 478 } | 500 } |
| 479 | 501 |
| 480 } // namespace app_list | 502 } // namespace app_list |
| OLD | NEW |