diff options
author | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-26 23:55:29 +0000 |
---|---|---|
committer | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-26 23:55:29 +0000 |
commit | 09911bf300f1a419907a9412154760efd0b7abc3 (patch) | |
tree | f131325fb4e2ad12c6d3504ab75b16dd92facfed /chrome/browser/browser_init.h | |
parent | 586acc5fe142f498261f52c66862fa417c3d52d2 (diff) | |
download | chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.zip chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.tar.gz chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.tar.bz2 |
Add chrome to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_init.h')
-rw-r--r-- | chrome/browser/browser_init.h | 207 |
1 files changed, 207 insertions, 0 deletions
diff --git a/chrome/browser/browser_init.h b/chrome/browser/browser_init.h new file mode 100644 index 0000000..6fe4658 --- /dev/null +++ b/chrome/browser/browser_init.h @@ -0,0 +1,207 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef CHROME_BROWSER_BROWSER_INIT_H__ +#define CHROME_BROWSER_BROWSER_INIT_H__ + +#include <atlbase.h> +#include <atlwin.h> +#include <windows.h> +#include <string> +#include <vector> + +#include "base/gfx/rect.h" +#include "chrome/browser/profile_manager.h" + +class Browser; +class CommandLine; +class GURL; +class Profile; +class TabContents; + +// Scoper class containing helpers for BrowserMain to spin up a new instance +// and initialize the profile. +class BrowserInit { + public: + // MessageWindow ------------------------------------------------------------- + // + // Class for dealing with the invisible global message window for IPC. This + // window allows different browser processes to communicate with each other. + // It is named according to the user data directory, so we can be sure that + // no more than one copy of the application can be running at once with a + // given data directory. + + class MessageWindow { + public: + explicit MessageWindow(const std::wstring& user_data_dir); + ~MessageWindow(); + + // Returns true if another process was found and notified, false if we + // should continue with this process. Roughly based on Mozilla + // + // TODO(brettw): this will not handle all cases. If two process start up too + // close to each other, the window might not have been created yet for the + // first one, so this function won't find it. + bool NotifyOtherProcess(int show_cmd); + + // Create the toplevel message window for IPC. + void Create(); + + // Blocks the dispatch of CopyData messages. + void Lock() { + locked_ = true; + } + + // Allows the dispatch of CopyData messages. + void Unlock() { + locked_ = false; + } + + // This ugly behemoth handles startup commands sent from another process. + LRESULT OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds); + + // Looks for zombie renderer and plugin processes that could have survived. + void HuntForZombieChromeProcesses(); + + private: + LRESULT CALLBACK WndProc(HWND hwnd, + UINT message, + WPARAM wparam, + LPARAM lparam); + + static LRESULT CALLBACK WndProcStatic(HWND hwnd, + UINT message, + WPARAM wparam, + LPARAM lparam) { + MessageWindow* msg_wnd = reinterpret_cast<MessageWindow*>( + GetWindowLongPtr(hwnd, GWLP_USERDATA)); + return msg_wnd->WndProc(hwnd, message, wparam, lparam); + } + + HWND remote_window_; // The HWND_MESSAGE of another browser. + HWND window_; // The HWND_MESSAGE window. + bool locked_; + + DISALLOW_EVIL_CONSTRUCTORS(MessageWindow); + }; + + // LaunchWithProfile --------------------------------------------------------- + // + // Assists launching the application and appending the initial tabs for a + // browser window. + + class LaunchWithProfile { + public: + LaunchWithProfile(const std::wstring& cur_dir, + const std::wstring& cmd_line, + int show_command); + ~LaunchWithProfile() { } + + // Creates the necessary windows for startup. Returns true on success, + // false on failure. process_startup is true if Chrome is just + // starting up. If process_startup is false, it indicates Chrome was + // already running and the user wants to launch another instance. + bool Launch(Profile* profile, bool process_startup); + + private: + // Creates a new tabbed browser. + // + // Note that the window returned by this function may not be visible yet. + Browser* CreateTabbedBrowser(); + + // 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 + // restored, and true is returned. + // . If the user's startup pref is to launch a specific set of URLs, and + // urls_to_open is empty, the user specified set of URLs is openned. + // + // Otherwise false is returned. + bool OpenStartupURLs(bool is_process_startup, + const CommandLine& command_line, + const std::vector<GURL>& urls_to_open); + + // Opens the list of urls. If browser is non-null and a tabbed browser, the + // URLs are opened in it. Otherwise a new tabbed browser is created and the + // URLs are added to it. The browser the tabs are added to is returned, + // which is either |browser| or the newly created browser. + Browser* OpenURLsInBrowser(Browser* browser, + bool process_startup, + const std::vector<GURL>& urls); + + // If the last session didn't exit cleanly and tab is a web contents tab, + // an infobar is added allowing the user to restore the last session. + void AddCrashedInfoBarIfNecessary(TabContents* tab); + + // Returns the list of URLs to open from the command line. The returned + // vector is empty if the user didn't specify any URLs on the command line. + std::vector<GURL> GetURLsFromCommandLine(const CommandLine& command_line, + Profile* profile); + + std::wstring cur_dir_; + std::wstring command_line_; + int show_command_; + Profile* profile_; + + // Bounds for the browser. + gfx::Rect start_position_; + + DISALLOW_EVIL_CONSTRUCTORS(LaunchWithProfile); + }; + + // 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 CommandLine& parsed_command_line, + const std::wstring& cur_dir, + PrefService* prefs, int show_command, + 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(const CommandLine& parsed_command_line, + Profile* profile, int show_command, + const std::wstring& cur_dir, bool process_startup, + int* return_code); + + template <class AutomationProviderClass> + static void CreateAutomationProvider(const std::wstring& channel_id, + Profile* profile, + size_t expected_tabs); + + private: + // This class is for scoping purposes. + BrowserInit(); + DISALLOW_EVIL_CONSTRUCTORS(BrowserInit); +}; + +#endif // CHROME_BROWSER_BROWSER_INIT_H__ |