diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser.cc | 51 | ||||
-rw-r--r-- | chrome/browser/browser.h | 16 | ||||
-rw-r--r-- | chrome/browser/browser.scons | 9 | ||||
-rw-r--r-- | chrome/browser/browser.vcproj | 24 | ||||
-rw-r--r-- | chrome/browser/browser_init.cc | 231 | ||||
-rw-r--r-- | chrome/browser/browser_init.h | 30 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 3 | ||||
-rw-r--r-- | chrome/browser/chrome_plugin_host.cc | 2 | ||||
-rw-r--r-- | chrome/browser/message_window.cc | 6 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents.cc | 51 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents.h | 27 | ||||
-rw-r--r-- | chrome/browser/views/constrained_window_impl.cc | 1 | ||||
-rw-r--r-- | chrome/browser/web_app.cc | 281 | ||||
-rw-r--r-- | chrome/browser/web_app.h | 159 | ||||
-rw-r--r-- | chrome/browser/web_app_icon_manager.cc | 115 | ||||
-rw-r--r-- | chrome/browser/web_app_icon_manager.h | 58 | ||||
-rw-r--r-- | chrome/browser/web_app_launcher.cc | 47 | ||||
-rw-r--r-- | chrome/browser/web_app_launcher.h | 41 | ||||
-rw-r--r-- | chrome/chrome.xcodeproj/project.pbxproj | 12 |
19 files changed, 158 insertions, 1006 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index d686f1f..d3b2d67 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -309,17 +309,13 @@ void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { } // static -void Browser::OpenWebApplication(Profile* profile, WebApp* app) { -#if defined(OS_WIN) - const std::wstring& app_name = - app->name().empty() ? ComputeApplicationNameFromURL(app->url()) : - app->name(); +void Browser::OpenApplicationWindow(Profile* profile, const GURL& url) { + std::wstring app_name = ComputeApplicationNameFromURL(url); RegisterAppPrefs(app_name); Browser* browser = Browser::CreateForApp(app_name, profile); - browser->AddWebApplicationTab(profile, app, false); + browser->AddTabWithURL(url, GURL(), PageTransition::START_PAGE, true, NULL); browser->window()->Show(); -#endif } /////////////////////////////////////////////////////////////////////////////// @@ -489,32 +485,6 @@ TabContents* Browser::AddTabWithURL( return contents; } -#if defined(OS_WIN) - -TabContents* Browser::AddWebApplicationTab(Profile* profile, - WebApp* web_app, - bool lazy) { - DCHECK(web_app); - - // TODO(acw): Do we need an "application launched" transition type? - // TODO(creis): Should we reuse the current instance (ie. process) here? - TabContents* contents = - CreateTabContentsForURL(web_app->url(), GURL(), profile, - PageTransition::LINK, lazy, NULL); - WebContents* web_contents = contents->AsWebContents(); - if (web_contents) - web_contents->SetWebApp(web_app); - - if (lazy) { - contents->controller()->LoadURLLazily( - web_app->url(), GURL(), PageTransition::LINK, web_app->name(), NULL); - } - tabstrip_model_.AddTabContents(contents, -1, PageTransition::LINK, !lazy); - return contents; -} - -#endif - TabContents* Browser::AddTabWithNavigationController( NavigationController* ctrl, PageTransition::Type type) { TabContents* tc = ctrl->active_contents(); @@ -1832,19 +1802,12 @@ bool Browser::IsApplication() const { } void Browser::ConvertContentsToApplication(TabContents* contents) { - WebContents* web_contents = contents->AsWebContents(); - if (!web_contents || !web_contents->web_app()) { - NOTREACHED(); - return; - } - int index = tabstrip_model_.GetIndexOfTabContents(contents); if (index < 0) return; - WebApp* app = web_contents->web_app(); - const std::wstring& app_name = app->name().empty() ? - ComputeApplicationNameFromURL(app->url()) : app->name(); + const GURL& url = contents->controller()->GetActiveEntry()->url(); + std::wstring app_name = ComputeApplicationNameFromURL(url); RegisterAppPrefs(app_name); tabstrip_model_.DetachTabContentsAt(index); @@ -2448,6 +2411,8 @@ void Browser::CloseFrame() { window_->Close(); } +#endif // OS_WIN + // static std::wstring Browser::ComputeApplicationNameFromURL(const GURL& url) { std::string t; @@ -2479,5 +2444,3 @@ void Browser::RegisterAppPrefs(const std::wstring& app_name) { prefs->RegisterDictionaryPref(window_pref.c_str()); } - -#endif // OS_WIN diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 8286cf23..ce81f5c 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -42,7 +42,6 @@ class PrefService; class Profile; class StatusBubble; class TabNavigation; -class WebApp; class Browser : public TabStripModelDelegate, public TabStripModelObserver, @@ -124,8 +123,8 @@ class Browser : public TabStripModelDelegate, // |profile|, that session is re-used. static void OpenURLOffTheRecord(Profile* profile, const GURL& url); - // Opens the a new application window for the specified WebApp. - static void OpenWebApplication(Profile* profile, WebApp* app); + // Opens the a new application ("thin frame") window for the specified url. + static void OpenApplicationWindow(Profile* profile, const GURL& url); // State Storage and Retrieval for UI /////////////////////////////////////// @@ -192,13 +191,6 @@ class Browser : public TabStripModelDelegate, PageTransition::Type transition, bool foreground, SiteInstance* instance); - // Add a new application tab for the specified URL. If lazy is true, the tab - // won't be selected. Further, the initial web page load will only take place - // when the tab is first selected. - TabContents* AddWebApplicationTab(Profile* profile, - WebApp* web_app, - bool lazy); - // Add a new tab, given a NavigationController. A TabContents appropriate to // display the last committed entry is created and returned. TabContents* AddTabWithNavigationController(NavigationController* ctrl, @@ -537,6 +529,8 @@ class Browser : public TabStripModelDelegate, // after a return to the message loop. void CloseFrame(); +#endif // OS_WIN + // Compute a deterministic name based on the URL. We use this pseudo name // as a key to store window location per application URLs. static std::wstring ComputeApplicationNameFromURL(const GURL& url); @@ -545,8 +539,6 @@ class Browser : public TabStripModelDelegate, // done only once per application name / per session. static void RegisterAppPrefs(const std::wstring& app_name); -#endif // OS_WIN - // Data members ///////////////////////////////////////////////////////////// // This Browser's type. diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons index 3af4093..0dfecdf 100644 --- a/chrome/browser/browser.scons +++ b/chrome/browser/browser.scons @@ -142,10 +142,6 @@ input_files = ChromeFileList([ 'user_data_manager.h', 'visitedlink_master.cc', 'visitedlink_master.h', - 'web_app.cc', - 'web_app.h', - 'web_app_launcher.cc', - 'web_app_launcher.h', ]), MSVSFilter('Bookmarks', [ 'bookmarks/bookmark_codec.cc', @@ -202,8 +198,6 @@ input_files = ChromeFileList([ 'task_manager.h', 'task_manager_resource_providers.cc', 'task_manager_resource_providers.h', - 'web_app_icon_manager.cc', - 'web_app_icon_manager.h', 'window_sizer.cc', 'window_sizer.h', ]), @@ -811,9 +805,6 @@ if not env.Bit('windows'): 'toolbar_model.cc', 'user_data_manager.cc', 'views/download_tab_view.cc', - 'web_app.cc', - 'web_app_icon_manager.cc', - 'web_app_launcher.cc', 'window_sizer.cc', ) diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index 253a164..80b2f6e 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -553,22 +553,6 @@ RelativePath=".\visitedlink_master.h" > </File> - <File - RelativePath=".\web_app.cc" - > - </File> - <File - RelativePath=".\web_app.h" - > - </File> - <File - RelativePath=".\web_app_launcher.cc" - > - </File> - <File - RelativePath=".\web_app_launcher.h" - > - </File> </Filter> <Filter Name="Bookmarks" @@ -794,14 +778,6 @@ > </File> <File - RelativePath=".\web_app_icon_manager.cc" - > - </File> - <File - RelativePath=".\web_app_icon_manager.h" - > - </File> - <File RelativePath=".\window_sizer.cc" > </File> diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index 1ef6a9b..443f0be 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -38,7 +38,6 @@ #include "chrome/browser/sessions/session_restore.h" #include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/navigation_controller.h" -#include "chrome/browser/web_app_launcher.h" #include "chrome/common/resource_bundle.h" #include "chromium_strings.h" @@ -103,26 +102,26 @@ class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate { DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate); }; -void SetOverrideHomePage(PrefService* prefs) { - const CommandLine* command_line = CommandLine::ForCurrentProcess(); +void SetOverrideHomePage(const CommandLine& command_line, + PrefService* prefs) { // If homepage is specified on the command line, canonify & store it. - if (command_line->HasSwitch(switches::kHomePage)) { + if (command_line.HasSwitch(switches::kHomePage)) { std::wstring browser_directory; PathService::Get(base::DIR_CURRENT, &browser_directory); std::wstring new_homepage = URLFixerUpper::FixupRelativeFile( browser_directory, - command_line->GetSwitchValue(switches::kHomePage)); + command_line.GetSwitchValue(switches::kHomePage)); prefs->transient()->SetString(prefs::kHomePage, new_homepage); prefs->transient()->SetBoolean(prefs::kHomePageIsNewTabPage, false); } } -SessionStartupPref GetSessionStartupPref(Profile* profile) { - const CommandLine* command_line = CommandLine::ForCurrentProcess(); +SessionStartupPref GetSessionStartupPref(const CommandLine& command_line, + Profile* profile) { SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile); - if (command_line->HasSwitch(switches::kRestoreLastSession)) + if (command_line.HasSwitch(switches::kRestoreLastSession)) pref.type = SessionStartupPref::LAST; - if (command_line->HasSwitch(switches::kIncognito) && + if (command_line.HasSwitch(switches::kIncognito) && pref.type == SessionStartupPref::LAST) { // We don't store session information when incognito. If the user has // chosen to restore last session and launched incognito, fallback to @@ -143,8 +142,11 @@ bool BrowserInit::InProcessStartup() { // LaunchWithProfile ---------------------------------------------------------- -BrowserInit::LaunchWithProfile::LaunchWithProfile(const std::wstring& cur_dir) - : cur_dir_(cur_dir) { +BrowserInit::LaunchWithProfile::LaunchWithProfile( + const std::wstring& cur_dir, + const CommandLine& command_line) + : cur_dir_(cur_dir), + command_line_(command_line) { } bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, @@ -152,19 +154,18 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, DCHECK(profile); profile_ = profile; - const CommandLine* command_line = CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(switches::kDnsLogDetails)) + if (command_line_.HasSwitch(switches::kDnsLogDetails)) chrome_browser_net::EnableDnsDetailedLog(true); - if (command_line->HasSwitch(switches::kDnsPrefetchDisable)) + if (command_line_.HasSwitch(switches::kDnsPrefetchDisable)) chrome_browser_net::EnableDnsPrefetch(false); - if (command_line->HasSwitch(switches::kDumpHistogramsOnExit)) + if (command_line_.HasSwitch(switches::kDumpHistogramsOnExit)) StatisticsRecorder::set_dump_on_exit(true); - if (command_line->HasSwitch(switches::kRemoteShellPort)) { + if (command_line_.HasSwitch(switches::kRemoteShellPort)) { if (!RenderProcessHost::run_renderer_in_process()) { std::wstring port_str = - command_line->GetSwitchValue(switches::kRemoteShellPort); + command_line_.GetSwitchValue(switches::kRemoteShellPort); int64 port = StringToInt64(port_str); if (port > 0 && port < 65535) { g_browser_process->InitDebuggerWrapper(static_cast<int>(port)); @@ -174,90 +175,72 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, } } - if (command_line->HasSwitch(switches::kEnableFileCookies)) + if (command_line_.HasSwitch(switches::kEnableFileCookies)) net::CookieMonster::EnableFileScheme(); - if (command_line->HasSwitch(switches::kUserAgent)) { + if (command_line_.HasSwitch(switches::kUserAgent)) { #if defined(OS_WIN) webkit_glue::SetUserAgent(WideToUTF8( - command_line->GetSwitchValue(switches::kUserAgent))); + command_line_.GetSwitchValue(switches::kUserAgent))); // TODO(port): hook this up when we bring in webkit. #endif } -#ifndef NDEBUG - if (command_line->HasSwitch(switches::kApp)) - NOTREACHED(); -#endif // NDEBUG - - std::vector<GURL> urls_to_open = GetURLsFromCommandLine(profile_); - - Browser* browser = NULL; - - // Always attempt to restore the last session. OpenStartupURLs only opens the - // home pages if no additional URLs were passed on the command line. - bool opened_startup_urls = OpenStartupURLs(process_startup, urls_to_open); - - if (!opened_startup_urls) { - if (urls_to_open.empty()) { - urls_to_open.push_back(GURL()); // New tab page. - PrefService* prefs = g_browser_process->local_state(); - if (prefs->IsPrefRegistered(prefs::kShouldShowWelcomePage) && - prefs->GetBoolean(prefs::kShouldShowWelcomePage)) { - // Reset the preference so we don't show the welcome page next time. - prefs->ClearPref(prefs::kShouldShowWelcomePage); - -#if defined(OS_WIN) - // Add the welcome page. - std::wstring welcome_url = l10n_util::GetString(IDS_WELCOME_PAGE_URL); - urls_to_open.push_back(GURL(welcome_url)); -#else - // TODO(port): implement welcome page. - NOTIMPLEMENTED(); -#endif - } - } else { - browser = BrowserList::GetLastActive(); + // Open the required browser windows and tabs. + // First, see if we're being run as a web application (thin frame window). + if (!OpenApplicationURL(profile)) { + std::vector<GURL> urls_to_open = GetURLsFromCommandLine(profile_); + // Always attempt to restore the last session. OpenStartupURLs only opens + // the home pages if no additional URLs were passed on the command line. + if (!OpenStartupURLs(process_startup, urls_to_open)) { + // Add the home page and any special first run URLs. + AddStartupURLs(&urls_to_open); + OpenURLsInBrowser(BrowserList::GetLastActive(), process_startup, + urls_to_open); } - - browser = OpenURLsInBrowser(browser, process_startup, urls_to_open); } - // It is possible to end here with a NULL 'browser'. For example if the user - // has tweaked the startup session restore preferences. + // If we're recording or playing back, startup the EventRecorder now + // unless otherwise specified. + if (!command_line_.HasSwitch(switches::kNoEvents)) { + std::wstring script_path; + PathService::Get(chrome::FILE_RECORDED_SCRIPT, &script_path); - if (browser) { - // If we're recording or playing back, startup the EventRecorder now - // unless otherwise specified. - if (!command_line->HasSwitch(switches::kNoEvents)) { - std::wstring script_path; - PathService::Get(chrome::FILE_RECORDED_SCRIPT, &script_path); + bool record_mode = command_line_.HasSwitch(switches::kRecordMode); + bool playback_mode = command_line_.HasSwitch(switches::kPlaybackMode); - bool record_mode = command_line->HasSwitch(switches::kRecordMode); - bool playback_mode = command_line->HasSwitch(switches::kPlaybackMode); - - if (record_mode && chrome::kRecordModeEnabled) - base::EventRecorder::current()->StartRecording(script_path); - if (playback_mode) - base::EventRecorder::current()->StartPlayback(script_path); - } + if (record_mode && chrome::kRecordModeEnabled) + base::EventRecorder::current()->StartRecording(script_path); + if (playback_mode) + base::EventRecorder::current()->StartPlayback(script_path); } return true; } +bool BrowserInit::LaunchWithProfile::OpenApplicationURL(Profile* profile) { + if (!command_line_.HasSwitch(switches::kApp)) + return false; + + GURL url(WideToUTF8(command_line_.GetSwitchValue(switches::kApp))); + if (!url.is_empty() && url.is_valid()) { + Browser::OpenApplicationWindow(profile, url); + return true; + } + return false; +} + bool BrowserInit::LaunchWithProfile::OpenStartupURLs( bool is_process_startup, const std::vector<GURL>& urls_to_open) { - const CommandLine* command_line = CommandLine::ForCurrentProcess(); - SessionStartupPref pref = GetSessionStartupPref(profile_); + SessionStartupPref pref = GetSessionStartupPref(command_line_, profile_); switch (pref.type) { case SessionStartupPref::LAST: if (!is_process_startup) return false; if (!profile_->DidLastSessionExitCleanly() && - !command_line->HasSwitch(switches::kRestoreLastSession)) { + !command_line_.HasSwitch(switches::kRestoreLastSession)) { // The last session crashed. It's possible automatically loading the // page will trigger another crash, locking the user out of chrome. // To avoid this, don't restore on startup but instead show the crashed @@ -317,8 +300,7 @@ void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary( std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine( Profile* profile) { std::vector<GURL> urls; - const CommandLine* command_line = CommandLine::ForCurrentProcess(); - std::vector<std::wstring> params = command_line->GetLooseValues(); + std::vector<std::wstring> params = command_line_.GetLooseValues(); for (size_t i = 0; i < params.size(); ++i) { std::wstring& value = params[i]; // Handle Vista way of searching - "? <search-term>" @@ -346,14 +328,39 @@ std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine( return urls; } +void BrowserInit::LaunchWithProfile::AddStartupURLs( + std::vector<GURL>* startup_urls) const { + // Otherwise open at least the new tab page (and the welcome page, if this + // is the first time the browser is being started), or the set of URLs + // specified on the command line. + if (startup_urls->empty()) { + startup_urls->push_back(GURL()); // New tab page. + PrefService* prefs = g_browser_process->local_state(); + if (prefs->IsPrefRegistered(prefs::kShouldShowWelcomePage) && + prefs->GetBoolean(prefs::kShouldShowWelcomePage)) { + // Reset the preference so we don't show the welcome page next time. + prefs->ClearPref(prefs::kShouldShowWelcomePage); + +#if defined(OS_WIN) + // Add the welcome page. + std::wstring welcome_url = l10n_util::GetString(IDS_WELCOME_PAGE_URL); + startup_urls->push_back(GURL(welcome_url)); +#else + // TODO(port): implement welcome page. + NOTIMPLEMENTED(); +#endif + } + } +} + bool BrowserInit::ProcessCommandLine( - const std::wstring& cur_dir, PrefService* prefs, bool process_startup, - Profile* profile, int* return_code) { + const CommandLine& command_line, const std::wstring& cur_dir, + PrefService* prefs, bool process_startup, Profile* profile, + int* return_code) { DCHECK(profile); - const CommandLine* command_line = CommandLine::ForCurrentProcess(); if (process_startup) { const std::wstring popup_count_string = - command_line->GetSwitchValue(switches::kOmniBoxPopupCount); + command_line.GetSwitchValue(switches::kOmniBoxPopupCount); if (!popup_count_string.empty()) { int count = 0; if (StringToInt(popup_count_string, &count)) { @@ -363,11 +370,11 @@ bool BrowserInit::ProcessCommandLine( } } - if (command_line->HasSwitch(switches::kDisablePromptOnRepost)) + if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) NavigationController::DisablePromptOnRepost(); const std::wstring tab_count_string = - command_line->GetSwitchValue(switches::kTabCountToLoadOnSessionRestore); + command_line.GetSwitchValue(switches::kTabCountToLoadOnSessionRestore); if (!tab_count_string.empty()) { int count = 0; if (StringToInt(tab_count_string, &count)) { @@ -378,9 +385,9 @@ bool BrowserInit::ProcessCommandLine( #if defined(OS_WIN) // Look for the testing channel ID ONLY during process startup - if (command_line->HasSwitch(switches::kTestingChannelID)) { + if (command_line.HasSwitch(switches::kTestingChannelID)) { std::wstring testing_channel_id = - command_line->GetSwitchValue(switches::kTestingChannelID); + command_line.GetSwitchValue(switches::kTestingChannelID); // TODO(sanjeevr) Check if we need to make this a singleton for // compatibility with the old testing code // If there are any loose parameters, we expect each one to generate a @@ -388,27 +395,27 @@ bool BrowserInit::ProcessCommandLine( CreateAutomationProvider<TestingAutomationProvider>( testing_channel_id, profile, - std::max(static_cast<int>(command_line->GetLooseValues().size()), + std::max(static_cast<int>(command_line.GetLooseValues().size()), 1)); } #endif } // Allow the command line to override the persisted setting of home page. - SetOverrideHomePage(profile->GetPrefs()); + SetOverrideHomePage(command_line, profile->GetPrefs()); - if (command_line->HasSwitch(switches::kBrowserStartRenderersManually)) + if (command_line.HasSwitch(switches::kBrowserStartRenderersManually)) prefs->transient()->SetBoolean(prefs::kStartRenderersManually, true); bool silent_launch = false; #if defined(OS_WIN) - if (command_line->HasSwitch(switches::kAutomationClientChannelID)) { + if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { std::wstring automation_channel_id = - command_line->GetSwitchValue(switches::kAutomationClientChannelID); + command_line.GetSwitchValue(switches::kAutomationClientChannelID); // If there are any loose parameters, we expect each one to generate a // new tab; if there are none then we have no tabs size_t expected_tabs = - std::max(static_cast<int>(command_line->GetLooseValues().size()), + std::max(static_cast<int>(command_line.GetLooseValues().size()), 0); if (expected_tabs == 0) silent_launch = true; @@ -421,9 +428,9 @@ bool BrowserInit::ProcessCommandLine( // TODO(port): figure out why this call crashes. #endif - if (command_line->HasSwitch(switches::kInstallExtension)) { + if (command_line.HasSwitch(switches::kInstallExtension)) { std::wstring path_string = - command_line->GetSwitchValue(switches::kInstallExtension); + command_line.GetSwitchValue(switches::kInstallExtension); FilePath path = FilePath::FromWStringHack(path_string); profile->GetExtensionsService()->InstallExtension(path); silent_launch = true; @@ -431,16 +438,19 @@ bool BrowserInit::ProcessCommandLine( // If we don't want to launch a new browser window or tab (in the case // of an automation request), we are done here. - if (!silent_launch) - return LaunchBrowser(profile, cur_dir, process_startup, return_code); + if (!silent_launch) { + return LaunchBrowser(command_line, profile, cur_dir, process_startup, + return_code); + } return true; } -bool BrowserInit::LaunchBrowser(Profile* profile, const std::wstring& cur_dir, +bool BrowserInit::LaunchBrowser(const CommandLine& command_line, + Profile* profile, const std::wstring& cur_dir, bool process_startup, int* return_code) { in_startup = process_startup; - bool result = LaunchBrowserImpl(profile, cur_dir, process_startup, - return_code); + bool result = LaunchBrowserImpl(command_line, profile, cur_dir, + process_startup, return_code); in_startup = false; return result; } @@ -461,40 +471,23 @@ void BrowserInit::CreateAutomationProvider(const std::wstring& channel_id, } #endif -bool BrowserInit::LaunchBrowserImpl(Profile* profile, +bool BrowserInit::LaunchBrowserImpl(const CommandLine& command_line, + Profile* profile, const std::wstring& cur_dir, bool process_startup, int* return_code) { DCHECK(profile); - const CommandLine* command_line = CommandLine::ForCurrentProcess(); - // Continue with the off-the-record profile from here on if --incognito - if (command_line->HasSwitch(switches::kIncognito)) + if (command_line.HasSwitch(switches::kIncognito)) profile = profile->GetOffTheRecordProfile(); - // Are we starting an application? - std::wstring app_url = command_line->GetSwitchValue(switches::kApp); - if (!app_url.empty()) { - GURL url(WideToUTF8(app_url)); - // If the application is started for a mailto:url, this machine has some - // old configuration that we should ignore. This hack saves us from some - // infinite loops where we keep forwarding mailto: to the system, resulting - // in the system asking us to open the mailto app. - if (url.SchemeIs("mailto")) - url = GURL("about:blank"); - - WebAppLauncher::Launch(profile, url); - return true; - } - - LaunchWithProfile lwp(cur_dir); + LaunchWithProfile lwp(cur_dir, command_line); bool launched = lwp.Launch(profile, process_startup); if (!launched) { LOG(ERROR) << "launch error"; - if (return_code != NULL) { + if (return_code != NULL) *return_code = ResultCodes::INVALID_CMDLINE_URL; - } return false; } diff --git a/chrome/browser/browser_init.h b/chrome/browser/browser_init.h index 6475b9f..fb3a5d6 100644 --- a/chrome/browser/browser_init.h +++ b/chrome/browser/browser_init.h @@ -11,6 +11,7 @@ #include "base/basictypes.h" class Browser; +class CommandLine; class GURL; class PrefService; class Profile; @@ -30,7 +31,8 @@ class BrowserInit { class LaunchWithProfile { public: - explicit LaunchWithProfile(const std::wstring& cur_dir); + LaunchWithProfile(const std::wstring& cur_dir, + const CommandLine& command_line); ~LaunchWithProfile() { } // Creates the necessary windows for startup. Returns true on success, @@ -40,6 +42,12 @@ class BrowserInit { bool Launch(Profile* profile, bool process_startup); private: + // If the process was launched with the web application command line flag, + // e.g. --app=http://www.google.com/, opens a web application browser and + // returns true. If there is no web application command line flag speciifed, + // returns false to specify default processing. + bool OpenApplicationURL(Profile* profile); + // Does the following: // . If the user's startup pref is to restore the last session (or the // command line flag is present to force using last session), it is @@ -67,7 +75,11 @@ class BrowserInit { // vector is empty if the user didn't specify any URLs on the command line. std::vector<GURL> GetURLsFromCommandLine(Profile* profile); + // Adds additional startup URLs to the specified vector. + void AddStartupURLs(std::vector<GURL>* startup_urls) const; + std::wstring cur_dir_; + const CommandLine& command_line_; Profile* profile_; DISALLOW_COPY_AND_ASSIGN(LaunchWithProfile); @@ -75,16 +87,19 @@ class BrowserInit { // This function performs command-line handling and is invoked when // process starts as well as when we get a start request from another - // process (via the WM_COPYDATA message). The process_startup flag - // indicates if this is being called from the process startup code or - // the WM_COPYDATA handler. - static bool ProcessCommandLine(const std::wstring& cur_dir, + // process (via the WM_COPYDATA message). |command_line| holds the command + // line we need to process - either from this process or from some other one + // (if |process_startup| is true and we are being called from + // MessageWindow::OnCopyData). + static bool ProcessCommandLine(const CommandLine& command_line, + const std::wstring& cur_dir, PrefService* prefs, bool process_startup, Profile* profile, int* return_code); // Helper function to launch a new browser based on command-line arguments // This function takes in a specific profile to use. - static bool LaunchBrowser(Profile* profile, const std::wstring& cur_dir, + static bool LaunchBrowser(const CommandLine& command_line, + Profile* profile, const std::wstring& cur_dir, bool process_startup, int* return_code); #if defined(OS_WIN) @@ -96,7 +111,8 @@ class BrowserInit { private: // Does the work of LaunchBrowser returning the result. - static bool LaunchBrowserImpl(Profile* profile, const std::wstring& cur_dir, + static bool LaunchBrowserImpl(const CommandLine& command_line, + Profile* profile, const std::wstring& cur_dir, bool process_startup, int* return_code); // This class is for scoping purposes. diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 84f1482..e3064a0 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -547,7 +547,8 @@ int BrowserMain(const MainFunctionParams& parameters) { if (parameters.ui_task) { MessageLoopForUI::current()->PostTask(FROM_HERE, parameters.ui_task); RunUIMessageLoop(browser_process.get()); - } else if (BrowserInit::ProcessCommandLine(std::wstring(), local_state, true, + } else if (BrowserInit::ProcessCommandLine(parsed_command_line, + std::wstring(), local_state, true, profile, &result_code)) { RunUIMessageLoop(browser_process.get()); } diff --git a/chrome/browser/chrome_plugin_host.cc b/chrome/browser/chrome_plugin_host.cc index 0e1ff11..38a941f 100644 --- a/chrome/browser/chrome_plugin_host.cc +++ b/chrome/browser/chrome_plugin_host.cc @@ -20,6 +20,7 @@ #include "chrome/browser/chrome_plugin_browsing_context.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/html_dialog_contents.h" +#include "chrome/browser/gears_integration.h" #include "chrome/browser/net/dns_master.h" #include "chrome/browser/plugin_process_host.h" #include "chrome/browser/plugin_service.h" @@ -31,6 +32,7 @@ #include "chrome/common/chrome_plugin_lib.h" #include "chrome/common/chrome_plugin_util.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/gears_api.h" #include "chrome/common/notification_service.h" #include "chrome/common/net/url_request_intercept_job.h" #include "chrome/common/plugin_messages.h" diff --git a/chrome/browser/message_window.cc b/chrome/browser/message_window.cc index 0375a5d..3bfced7 100644 --- a/chrome/browser/message_window.cc +++ b/chrome/browser/message_window.cc @@ -209,7 +209,11 @@ LRESULT MessageWindow::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) { NOTREACHED(); return TRUE; } - BrowserInit::ProcessCommandLine(cur_dir, prefs, false, profile, NULL); + + // Run the browser startup sequence again, with the command line of the + // signalling process. + BrowserInit::ProcessCommandLine(parsed_command_line, cur_dir, prefs, false, + profile, NULL); return TRUE; } return TRUE; diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc index 589c0cb..039ddc2 100644 --- a/chrome/browser/tab_contents/web_contents.cc +++ b/chrome/browser/tab_contents/web_contents.cc @@ -17,6 +17,7 @@ #include "chrome/browser/dom_operation_notification_details.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_request_manager.h" +#include "chrome/browser/gears_integration.h" #include "chrome/browser/google_util.h" #include "chrome/browser/js_before_unload_handler.h" #include "chrome/browser/jsmessage_box_handler.h" @@ -215,8 +216,6 @@ WebContents::WebContents(Profile* profile, } WebContents::~WebContents() { - if (web_app_.get()) - web_app_->RemoveObserver(this); if (pending_install_.callback_functor) pending_install_.callback_functor->Cancel(); NotificationService::current()->RemoveObserver( @@ -329,15 +328,6 @@ SiteInstance* WebContents::GetSiteInstance() const { return render_manager_.current_host()->site_instance(); } -SkBitmap WebContents::GetFavIcon() { - if (web_app_.get() && IsWebApplicationActive()) { - SkBitmap app_icon = web_app_->GetFavIcon(); - if (!app_icon.isNull()) - return app_icon; - } - return TabContents::GetFavIcon(); -} - std::wstring WebContents::GetStatusText() const { if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE) return std::wstring(); @@ -499,23 +489,6 @@ void WebContents::GetContainerBounds(gfx::Rect *out) const { view_->GetContainerBounds(out); } -void WebContents::SetWebApp(WebApp* web_app) { - if (web_app_.get()) { - web_app_->RemoveObserver(this); - web_app_->SetWebContents(NULL); - } - - web_app_ = web_app; - if (web_app) { - web_app->AddObserver(this); - web_app_->SetWebContents(this); - } -} - -bool WebContents::IsWebApplication() const { - return (web_app_.get() != NULL); -} - void WebContents::CreateShortcut() { NavigationEntry* entry = controller()->GetLastCommittedEntry(); if (!entry) @@ -941,8 +914,6 @@ void WebContents::DidDownloadImage( fav_icon_helper_.FavIconDownloadFailed(id); else fav_icon_helper_.SetFavIcon(id, image_url, image); - if (web_app_.get() && !errored) - web_app_->SetImage(image_url, image); } void WebContents::RequestOpenURL(const GURL& url, const GURL& referrer, @@ -1544,25 +1515,6 @@ void WebContents::UpdateWebPreferences() { render_view_host()->UpdateWebPreferences(GetWebkitPrefs()); } -bool WebContents::IsWebApplicationActive() const { - if (!web_app_.get()) - return false; - - // If we are inside an application, the application is always active. For - // example, this allows us to display the GMail icon even when we are bounced - // the login page. - if (delegate() && delegate()->IsApplication()) - return true; - - return (GetURL() == web_app_->url()); -} - -void WebContents::WebAppImagesChanged(WebApp* web_app) { - DCHECK(web_app == web_app_.get()); - if (delegate() && IsWebApplicationActive()) - delegate()->NavigationStateChanged(this, TabContents::INVALIDATE_FAVICON); -} - void WebContents::OnGearsCreateShortcutDone( const GearsShortcutData& shortcut_data, bool success) { NavigationEntry* current_entry = controller()->GetLastCommittedEntry(); @@ -1572,7 +1524,6 @@ void WebContents::OnGearsCreateShortcutDone( if (success && same_page) { // Only switch to app mode if the user chose to create a shortcut and // we're still on the same page that it corresponded to. - SetWebApp(new WebApp(profile(), shortcut_data)); if (delegate()) delegate()->ConvertContentsToApplication(this); } diff --git a/chrome/browser/tab_contents/web_contents.h b/chrome/browser/tab_contents/web_contents.h index 55f1ee7..39bf2c6 100644 --- a/chrome/browser/tab_contents/web_contents.h +++ b/chrome/browser/tab_contents/web_contents.h @@ -12,7 +12,7 @@ #include "chrome/browser/tab_contents/render_view_host_manager.h" #include "chrome/browser/shell_dialogs.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/web_app.h" +#include "chrome/common/gears_api.h" class AutofillManager; class InterstitialPageDelegate; @@ -32,8 +32,7 @@ class WaitableEvent; class WebContents : public TabContents, public RenderViewHostDelegate, public RenderViewHostManager::Delegate, - public SelectFileDialog::Listener, - public WebApp::Observer { + public SelectFileDialog::Listener { public: // If instance is NULL, then creates a new process for this view. Otherwise // initialize with a process already created for a different WebContents. @@ -88,7 +87,6 @@ class WebContents : public TabContents, virtual void Destroy(); virtual WebContents* AsWebContents() { return this; } virtual SiteInstance* GetSiteInstance() const; - virtual SkBitmap GetFavIcon(); virtual std::wstring GetStatusText() const; virtual bool NavigateToPendingEntry(bool reload); virtual void Stop(); @@ -113,13 +111,6 @@ class WebContents : public TabContents, // Web apps ------------------------------------------------------------------ - // Sets the WebApp for this WebContents. - void SetWebApp(WebApp* web_app); - WebApp* web_app() { return web_app_.get(); } - - // Return whether this tab contents was created to contain an application. - bool IsWebApplication() const; - // Tell Gears to create a shortcut for the current page. void CreateShortcut(); @@ -431,17 +422,6 @@ class WebContents : public TabContents, // Send webkit specific settings to the renderer. void UpdateWebPreferences(); - // Return whether the optional web application is active for the current URL. - // Call this method to check if web app properties are in effect. - // - // Note: This method should be used for presentation but not security. The app - // is always active if the containing window is a web application. - bool IsWebApplicationActive() const; - - // WebApp::Observer method. Invoked when the set of images contained in the - // web app changes. Notifies the delegate our favicon has changed. - virtual void WebAppImagesChanged(WebApp* web_app); - // Called when the user dismisses the shortcut creation dialog. 'success' is // true if the shortcut was created. void OnGearsCreateShortcutDone(const GearsShortcutData& shortcut_data, @@ -566,9 +546,6 @@ class WebContents : public TabContents, net::LoadState load_state_; std::wstring load_state_host_; - // Non-null if we're displaying content for a web app. - scoped_refptr<WebApp> web_app_; - DISALLOW_COPY_AND_ASSIGN(WebContents); }; diff --git a/chrome/browser/views/constrained_window_impl.cc b/chrome/browser/views/constrained_window_impl.cc index 2cae93d..de00ad2 100644 --- a/chrome/browser/views/constrained_window_impl.cc +++ b/chrome/browser/views/constrained_window_impl.cc @@ -14,7 +14,6 @@ #include "chrome/browser/tab_contents/web_contents_view.h" #include "chrome/browser/toolbar_model.h" #include "chrome/browser/views/frame/browser_view.h" -#include "chrome/browser/web_app.h" #include "chrome/browser/window_sizer.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/gfx/chrome_canvas.h" diff --git a/chrome/browser/web_app.cc b/chrome/browser/web_app.cc deleted file mode 100644 index 10f7e35..0000000 --- a/chrome/browser/web_app.cc +++ /dev/null @@ -1,281 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/web_app.h" - -#include "base/gfx/png_decoder.h" -#include "chrome/browser/profile.h" -#include "chrome/browser/renderer_host/render_view_host.h" -#include "chrome/browser/tab_contents/web_contents.h" -#include "chrome/common/gfx/favicon_size.h" -#include "net/base/base64.h" -#include "net/base/data_url.h" - -namespace { - -static const char kPNGImageMimeType[] = "image/png"; - -static std::set<GURL> ExtractImageURLs(const GearsShortcutData& data) { - std::set<GURL> image_urls; - for (size_t i = 0; i < arraysize(data.icons); ++i) { - if (data.icons[i].url) { - GURL image_url(data.icons[i].url); - if (image_url.is_valid()) - image_urls.insert(image_url); - else - NOTREACHED(); - } - } - return image_urls; -} - -static SkBitmap DecodePNGEncodedURL(const GURL& url) { - std::string mime_type, charset, data; - if (!url.SchemeIs("data") || - !net::DataURL::Parse(url, &mime_type, &charset, &data) || - mime_type != kPNGImageMimeType) { - return SkBitmap(); - } - - SkBitmap image; - std::vector<unsigned char> v_data; - v_data.resize(data.size(), 0); - memcpy(&v_data.front(), data.c_str(), data.size()); - PNGDecoder::Decode(&v_data, &image); - return image; -} - -} // namespace - -// WebApp ---------------------------------------------------------------------- - -WebApp::WebApp(Profile* profile, - const GURL& url, - const std::wstring& name) - : web_contents_(NULL), - profile_(profile), - url_(url), - name_(name), - loaded_images_from_web_data_(false), - image_load_handle_(0), - download_images_(false) { -} - -WebApp::WebApp(Profile* profile, - const GearsShortcutData& shortcut) - : web_contents_(NULL), - profile_(profile), - url_(shortcut.url), - name_(shortcut.name ? UTF8ToWide(shortcut.name) : std::wstring()), - loaded_images_from_web_data_(false), - image_load_handle_(0), - image_urls_(ExtractImageURLs(shortcut)), - download_images_(!image_urls_.empty()) { - ExtractPNGEncodedURLs(); - // If the image urls are all data encoded urls and at least one is favicon - // sized, then no need to load/store in web data. - loaded_images_from_web_data_ = (GetFavIconIterator() != images_.end() && - image_urls_.empty()); -} - -WebApp::~WebApp() { - if (image_load_handle_) { - WebDataService* service = - profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); - if (service) - service->CancelRequest(image_load_handle_); - } -} - -void WebApp::SetImage(const GURL& image_url, const SkBitmap& image) { - std::set<GURL>::iterator i = image_urls_.find(image_url); - if (i == image_urls_.end()) - return; // We didn't request the url. - - if (image.width() == 0 || image.height() == 0) { - // Assume there was an error downloading. By ignoring this we ensure we - // attempt to download the image next time user launches the app. - return; - } - - image_urls_.erase(i); - - WebDataService* service = - profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); - - if (!image.isNull()) { - if (image.width() == kFavIconSize && image.height() == kFavIconSize) { - Images::iterator fav_icon_i = GetFavIconIterator(); - if (fav_icon_i != images_.end()) - images_.erase(fav_icon_i); // Only allow one favicon. - } - images_.push_back(image); - NotifyObservers(); - if (service) - service->SetWebAppImage(url_, image); - } - - if (service && image_urls_.empty()) - service->SetWebAppHasAllImages(url_, true); -} - -const WebApp::Images& WebApp::GetImages() { - LoadImagesFromWebData(); - - return images_; -} - -SkBitmap WebApp::GetFavIcon() { - // Force a load. - GetImages(); - - Images::iterator fav_icon_i = GetFavIconIterator(); - return (fav_icon_i == images_.end()) ? SkBitmap() : *fav_icon_i; -} - -void WebApp::SetWebContents(WebContents* host) { - web_contents_ = host; - - if (host && loaded_images_from_web_data_ && image_load_handle_ == 0 && - !image_urls_.empty()) { - // We haven't downloaded all the images and got a new WebContents. Download - // the images from it. - DownloadImagesFromSite(); - } -} - -void WebApp::AddObserver(Observer* obs) { - observer_list_.AddObserver(obs); -} - -void WebApp::RemoveObserver(Observer* obs) { - observer_list_.RemoveObserver(obs); -} - -void WebApp::LoadImagesFromWebData() { - if (loaded_images_from_web_data_) - return; - - loaded_images_from_web_data_ = true; - WebDataService* service = - profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); - if (service) - image_load_handle_ = service->GetWebAppImages(url_, this); -} - -void WebApp::OnWebDataServiceRequestDone(WebDataService::Handle h, - const WDTypedResult* r) { - image_load_handle_ = 0; - - if (!r) { - // Results are null if the database went away. - return; - } - - WDAppImagesResult result = reinterpret_cast< - const WDResult<WDAppImagesResult>*>(r)->GetValue(); - images_.insert(images_.end(), result.images.begin(), result.images.end()); - - if (!result.has_all_images) { - // Not all of the images for the app have been downloaded yet; download them - // now. - DownloadImagesFromSite(); - } else { - // We have all the images. Clear image_urls_ to indicate we've got all the - // images. - image_urls_.clear(); - } - - if (GetFavIconIterator() == images_.end()) { - // No favicon. Request one from the history db. - LoadFavIconFromHistory(); - } - - if (!images_.empty()) - NotifyObservers(); -} - -void WebApp::OnFavIconFromHistory(HistoryService::Handle handle, - bool know_favicon, - scoped_refptr<RefCountedBytes> data, - bool expired, - GURL icon_url) { - // Make sure we still don't have a favicon. - if (GetFavIconIterator() != images_.end() || !data || data->data.empty()) - return; - - SkBitmap fav_icon; - if (PNGDecoder::Decode(&data->data, &fav_icon)) { - images_.push_back(fav_icon); - NotifyObservers(); - } -} - -void WebApp::LoadFavIconFromHistory() { - HistoryService* service = - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (!service) - return; - - service->GetFavIconForURL(url_, &request_consumer_, - NewCallback(this, &WebApp::OnFavIconFromHistory)); -} - -void WebApp::DownloadImagesFromSite() { - if (!download_images_) - return; - - RenderViewHost* rvh = - web_contents_ ? web_contents_->render_view_host() : NULL; - if (!rvh) - return; - - // Copy off the images to load as we may need to mutate image_urls_ while - // iterating. - std::set<GURL> image_urls = image_urls_; - for (std::set<GURL>::iterator i = image_urls.begin(); i != image_urls.end(); - ++i) { - const GURL image_url = *i; - SkBitmap data_image = DecodePNGEncodedURL(image_url); - if (!data_image.isNull()) - SetImage(image_url, data_image); - else if (rvh) - rvh->DownloadImage(image_url, 0); // Download the image via the renderer. - } - - if (image_urls_.empty()) { - // We got all the images immediately, notifiy the web db. - WebDataService* service = - profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); - if (service) - service->SetWebAppHasAllImages(url_, true); - } -} - -WebApp::Images::iterator WebApp::GetFavIconIterator() { - for (Images::iterator i = images_.begin(); i != images_.end(); ++i) { - if (i->width() == kFavIconSize && i->height() == kFavIconSize) - return i; - } - return images_.end(); -} - -void WebApp::ExtractPNGEncodedURLs() { - for (std::set<GURL>::iterator i = image_urls_.begin(); - i != image_urls_.end();) { - const GURL image_url = *i; - SkBitmap data_image = DecodePNGEncodedURL(image_url); - if (!data_image.isNull()) { - i = image_urls_.erase(i); - images_.push_back(data_image); - } else { - ++i; - } - } -} - -void WebApp::NotifyObservers() { - FOR_EACH_OBSERVER(Observer, observer_list_, WebAppImagesChanged(this)); -} - diff --git a/chrome/browser/web_app.h b/chrome/browser/web_app.h deleted file mode 100644 index 394481f..0000000 --- a/chrome/browser/web_app.h +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_WEB_APP_H__ -#define CHROME_BROWSER_WEB_APP_H__ - -#include <vector> - -#include "base/ref_counted.h" -#include "chrome/browser/cancelable_request.h" -#include "chrome/browser/gears_integration.h" -#include "chrome/browser/history/history.h" -#include "chrome/browser/webdata/web_data_service.h" -#include "googleurl/src/gurl.h" -#include "skia/include/SkBitmap.h" - -class Profile; -class WebContents; - -// A WebApp represents a page that Gears has installed a shortcut for. A WebApp -// has a name, url and set of images (potentially empty). The images are lazily -// loaded when asked for. -// -// The images are first loaded from the WebDatabase. If the images are not in -// the WebDB, the list of images is obtained from Gears then downloaded via the -// WebContents set by SetWebContents. As images are loaded they are pushed to -// the WebDatabase. Observers are notified any time the set of images changes. -class WebApp : public base::RefCounted<WebApp>, public WebDataServiceConsumer { - public: - typedef std::vector<SkBitmap> Images; - - // The Observer is notified any time the set of images contained in the WebApp - // changes. - class Observer { - public: - virtual void WebAppImagesChanged(WebApp* web_app) = 0; - }; - - // Creates a WebApp by name and url. This variant is only used if Gears - // doesn't know about the shortcut. - WebApp(Profile* profile, - const GURL& url, - const std::wstring& name); - - // Creates a WebApp from a Gears shortcut. - WebApp(Profile* profile, - const GearsShortcutData& shortcut); - ~WebApp(); - - // Sets the specified image. This is invoked from the WebContents when an - // image finishes downloading. If image_url is one of the images this WebApp - // asked to download, it is pushed to the database and the observer is - // notified. If the image isn't one that was asked for by this WebApp, nothing - // happens. - void SetImage(const GURL& image_url, const SkBitmap& image); - - // Returns the set of images. If the images haven't been loaded yet, they are - // asked for. - const Images& GetImages(); - - // Convenience to get the favicon from the set of images. If a favicon sized - // image isn't found, an empty image is returned. - SkBitmap GetFavIcon(); - - // Name of the app. - const std::wstring& name() const { return name_; } - - // URL to the app. - const GURL& url() const { return url_; } - - // Sets the WebContents that is using this WebApp. This is used if the - // database doesn't have all the images. If NULL, images won't be downloaded - // if they aren't in the db. - void SetWebContents(WebContents* host); - - // WebContents used to download images; may be null. - WebContents* web_contents() { return web_contents_; } - - void AddObserver(Observer* obs); - void RemoveObserver(Observer* obs); - - private: - // Requests the images for this app from the web db. Does nothing if the - // images have already been requested. - void LoadImagesFromWebData(); - - // Notification from the WebDB that our request for the images has completed. - // This adds all the images from the request to this WebApp, and if not all - // images have been downloaded, the images are requested from the webContents. - // Similarly if a favicon sized image isn't available, one is asked for from - // history. - virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, - const WDTypedResult* result); - - // Callback from history when the favicon is available. If we don't have a - // favicon sized image, the image is added to this WebApp's list of images. - void OnFavIconFromHistory(HistoryService::Handle handle, - bool know_favicon, - scoped_refptr<RefCountedBytes> data, - bool expired, - GURL icon_url); - - // Requests the favicon from history. - void LoadFavIconFromHistory(); - - // Asks the hosting WebApp to download all the images. - void DownloadImagesFromSite(); - - // Returns the position of the favicon, or images_.end() if no favicon sized - // image is available - Images::iterator GetFavIconIterator(); - - // An URLs in image_urls_ that are data encoded PNGs are extracted and added - // to images_. - void ExtractPNGEncodedURLs(); - - void NotifyObservers(); - - // WebContents used to download images, may be null. - WebContents* web_contents_; - - // Profile used for WebDataservice and History. - Profile* profile_; - - // URL of the app. - const GURL url_; - - // Name of the app. - const std::wstring name_; - - // Have the images been loaded from the WebDB? This is initially false and set - // true when GetImages is invoked. - bool loaded_images_from_web_data_; - - // If non-zero, indicates we have a loading pending from the WebDB. - WebDataService::Handle image_load_handle_; - - // Set of images. - Images images_; - - // Set of image urls. - std::set<GURL> image_urls_; - - // Should the images be downloaded from the page? This is false if we don't - // know the set of image urls (weren't created from a GearsShortcutData) or - // the image urls in the GearsShortcutData were empty. - bool download_images_; - - // Used for history request for the favicon. - CancelableRequestConsumer request_consumer_; - - ObserverList<Observer> observer_list_; - - DISALLOW_EVIL_CONSTRUCTORS(WebApp); -}; - -#endif // CHROME_BROWSER_WEB_APP_H__ - diff --git a/chrome/browser/web_app_icon_manager.cc b/chrome/browser/web_app_icon_manager.cc deleted file mode 100644 index 3d12aed..0000000 --- a/chrome/browser/web_app_icon_manager.cc +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/web_app_icon_manager.h" - -#include "chrome/app/chrome_dll_resource.h" -#include "chrome/app/theme/theme_resources.h" -#include "chrome/browser/tab_contents/web_contents.h" -#include "chrome/common/gfx/icon_util.h" -#include "skia/include/SkBitmap.h" - -// Returns the default icon for the window. -static HICON GetDefaultIcon() { - HMODULE chrome_dll = GetModuleHandle(L"chrome.dll"); - return ::LoadIcon(chrome_dll, MAKEINTRESOURCE(IDR_MAINFRAME)); -} - -// Updates the icon of the window from the specified SkBitmap. If the image -// is empty, the default icon is used. If icon is non-null it is updated to -// reflect the new icon (unless the default is used). -static void UpdateIcon(HWND hwnd, - const SkBitmap& image, - int icon_type, - HICON* icon) { - if (icon) { - if (*icon) - DestroyIcon(*icon); - *icon = NULL; - } - - HICON icon_to_set; - if (image.width() > 0) { - icon_to_set = IconUtil::CreateHICONFromSkBitmap(image); - if (icon) - *icon = icon_to_set; - } else { - icon_to_set = GetDefaultIcon(); - } - ::SendMessage(hwnd, WM_SETICON, icon_type, - reinterpret_cast<LPARAM>(icon_to_set)); -} - -WebAppIconManager::WebAppIconManager(HWND parent) - : hwnd_(parent), small_icon_(NULL), big_icon_(NULL), enabled_(true) { -} - -WebAppIconManager::~WebAppIconManager() { - if (small_icon_) - DestroyIcon(small_icon_); - - if (big_icon_) - DestroyIcon(big_icon_); - - if (app_.get()) - app_->RemoveObserver(this); -} - -void WebAppIconManager::SetContents(TabContents* contents) { - WebApp* new_app = NULL; - if (contents && contents->AsWebContents()) - new_app = contents->AsWebContents()->web_app(); - - if (new_app == app_.get()) - return; - - if (app_.get()) - app_->RemoveObserver(this); - app_ = new_app; - if (app_.get()) { - app_->AddObserver(this); - UpdateIconsFromApp(); - } else if (enabled_) { - UpdateIcon(hwnd_, SkBitmap(), ICON_SMALL, NULL); - UpdateIcon(hwnd_, SkBitmap(), ICON_BIG, NULL); - } -} - -void WebAppIconManager::SetUpdatesEnabled(bool enabled) { - if (enabled == enabled_) - return; - - enabled_ = enabled; - if (enabled_) - UpdateIconsFromApp(); -} - -void WebAppIconManager::WebAppImagesChanged(WebApp* web_app) { - UpdateIconsFromApp(); -} - -void WebAppIconManager::UpdateIconsFromApp() { - if (!enabled_) - return; - - SkBitmap small_image; - SkBitmap big_image; - if (app_.get() && !app_->GetImages().empty()) { - const WebApp::Images& images = app_->GetImages(); - WebApp::Images::const_iterator smallest = images.begin(); - WebApp::Images::const_iterator biggest = images.begin(); - for (WebApp::Images::const_iterator i = images.begin() + 1; - i != images.end(); ++i) { - if (i->width() > biggest->width()) - biggest = i; - else if (i->width() > 0 && i->width() < smallest->width()) - smallest = i; - } - small_image = *smallest; - big_image = *biggest; - } - UpdateIcon(hwnd_, small_image, ICON_SMALL, &small_icon_); - UpdateIcon(hwnd_, big_image, ICON_BIG, &big_icon_); -} - diff --git a/chrome/browser/web_app_icon_manager.h b/chrome/browser/web_app_icon_manager.h deleted file mode 100644 index 3f8d245..0000000 --- a/chrome/browser/web_app_icon_manager.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_WEB_APP_ICON_MANAGER_H__ -#define CHROME_BROWSER_WEB_APP_ICON_MANAGER_H__ - -#include <windows.h> - -#include "base/scoped_ptr.h" -#include "chrome/browser/web_app.h" - -class TabContents; - -// WebAppIconManager is used by SimpleXPFrame/SimpleVistaFrame to manage the -// icons for the frame. If the current contents are a web app, then icon is -// set from the app, otherwise the icons are set to the default. -class WebAppIconManager : public WebApp::Observer { - public: - explicit WebAppIconManager(HWND parent); - ~WebAppIconManager(); - - // Sets the contents the WebApp should come from. If the contents has a web - // app, the image comes from it, otherwise the icon for the HWND is set to - // the default chrome icon. - void SetContents(TabContents* contents); - - // Enables/disables icons. If true and this WebAppIconManager was previously - // disabled, the icon is updated immediately. - void SetUpdatesEnabled(bool enabled); - - private: - // Invoked when the icons of the WebApp has changed. Invokes - // UpdateIconsFromApp appropriately. - virtual void WebAppImagesChanged(WebApp* web_app); - - // Updates the icons of the HWND, unless we're disabled in which case this - // does nothing. - void UpdateIconsFromApp(); - - // HWND the icon is updated on. - const HWND hwnd_; - - // Current app, may be null. - scoped_refptr<WebApp> app_; - - // Icons. These are only valid if the app doesn't have an icon. - HICON small_icon_; - HICON big_icon_; - - // Are we enabled? If not, we won't update the icons of the HWND. - bool enabled_; - - DISALLOW_EVIL_CONSTRUCTORS(WebAppIconManager); -}; - -#endif // CHROME_BROWSER_WEB_APP_ICON_MANAGER_H__ - diff --git a/chrome/browser/web_app_launcher.cc b/chrome/browser/web_app_launcher.cc deleted file mode 100644 index f783ea9..0000000 --- a/chrome/browser/web_app_launcher.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/web_app_launcher.h" - -#include "base/string_util.h" -#include "chrome/browser/browser.h" -#include "chrome/browser/profile.h" -#include "chrome/browser/web_app.h" - -// static -void WebAppLauncher::Launch(Profile* profile, const GURL& url) { - (new WebAppLauncher(profile, url))->Run(); -} - -WebAppLauncher::WebAppLauncher(Profile* profile, const GURL& url) - : profile_(profile), - url_(url) { -} - -void WebAppLauncher::Run() { - GearsQueryShortcuts(NewCallback(this, &WebAppLauncher::OnGotApps)); -} - -void WebAppLauncher::OnGotApps(GearsShortcutList* apps) { - WebApp* app = NULL; - - if (apps) { - for (size_t i = 0; i < apps->num_shortcuts; ++i) { - if (apps->shortcuts[i].url && GURL(apps->shortcuts[i].url) == url_) { - app = new WebApp(profile_, apps->shortcuts[i]); - break; - } - } - } - - if (!app) { - // Gears doesn't know about this app. Create one anyway. - app = new WebApp(profile_, url_, std::wstring()); - } - - Browser::OpenWebApplication(profile_, app); - - delete this; -} - diff --git a/chrome/browser/web_app_launcher.h b/chrome/browser/web_app_launcher.h deleted file mode 100644 index 7b377bf..0000000 --- a/chrome/browser/web_app_launcher.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_WEB_APP_LAUNCHER_H__ -#define CHROME_BROWSER_WEB_APP_LAUNCHER_H__ - -#include "chrome/browser/gears_integration.h" -#include "googleurl/src/gurl.h" - -class Profile; - -// WebAppLauncher is used during startup to launch a web app (aka an installed -// app). -class WebAppLauncher { - public: - // Queries Gears for the name of the app, and when Gears callsback with the - // response creates a WebApp and Browser. - static void Launch(Profile* profile, const GURL& url); - - private: - WebAppLauncher(Profile* profile, const GURL& url); - - // Invoked from the Launch method. Queries Gears for the apps. Gears callback - // to OnGotApps. - void Run(); - - // Callback from Gears when list of apps is available. Creates WebApp and - // Browser. - void OnGotApps(GearsShortcutList* apps); - - Profile* profile_; - - // URL of the app. - const GURL url_; - - DISALLOW_EVIL_CONSTRUCTORS(WebAppLauncher); -}; - -#endif // CHROME_BROWSER_WEB_APP_LAUNCHER_H__ - diff --git a/chrome/chrome.xcodeproj/project.pbxproj b/chrome/chrome.xcodeproj/project.pbxproj index af82b2a..045efe0 100644 --- a/chrome/chrome.xcodeproj/project.pbxproj +++ b/chrome/chrome.xcodeproj/project.pbxproj @@ -1503,12 +1503,6 @@ 4D7BF9600E9D4839009A6919 /* visitedlink_master.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = visitedlink_master.h; sourceTree = "<group>"; }; 4D7BF9610E9D4839009A6919 /* visitedlink_perftest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = visitedlink_perftest.cc; sourceTree = "<group>"; }; 4D7BF9620E9D4839009A6919 /* visitedlink_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = visitedlink_unittest.cc; sourceTree = "<group>"; }; - 4D7BF9630E9D4839009A6919 /* web_app.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = web_app.cc; sourceTree = "<group>"; }; - 4D7BF9640E9D4839009A6919 /* web_app.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = web_app.h; sourceTree = "<group>"; }; - 4D7BF9650E9D4839009A6919 /* web_app_icon_manager.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = web_app_icon_manager.cc; sourceTree = "<group>"; }; - 4D7BF9660E9D4839009A6919 /* web_app_icon_manager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = web_app_icon_manager.h; sourceTree = "<group>"; }; - 4D7BF9670E9D4839009A6919 /* web_app_launcher.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = web_app_launcher.cc; sourceTree = "<group>"; }; - 4D7BF9680E9D4839009A6919 /* web_app_launcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = web_app_launcher.h; sourceTree = "<group>"; }; 4D7BF9700E9D4839009A6919 /* window_sizer.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = window_sizer.cc; sourceTree = "<group>"; }; 4D7BF9710E9D4839009A6919 /* window_sizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = window_sizer.h; sourceTree = "<group>"; }; 4D7BF9720E9D4839009A6919 /* window_sizer_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = window_sizer_unittest.cc; sourceTree = "<group>"; }; @@ -2680,12 +2674,6 @@ 4D7BF9600E9D4839009A6919 /* visitedlink_master.h */, 4D7BF9610E9D4839009A6919 /* visitedlink_perftest.cc */, 4D7BF9620E9D4839009A6919 /* visitedlink_unittest.cc */, - 4D7BF9630E9D4839009A6919 /* web_app.cc */, - 4D7BF9640E9D4839009A6919 /* web_app.h */, - 4D7BF9650E9D4839009A6919 /* web_app_icon_manager.cc */, - 4D7BF9660E9D4839009A6919 /* web_app_icon_manager.h */, - 4D7BF9670E9D4839009A6919 /* web_app_launcher.cc */, - 4D7BF9680E9D4839009A6919 /* web_app_launcher.h */, 4D7BF9700E9D4839009A6919 /* window_sizer.cc */, 4D7BF9710E9D4839009A6919 /* window_sizer.h */, 4D7BF9720E9D4839009A6919 /* window_sizer_unittest.cc */, |