| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_FRAME_CHROME_FRAME_PLUGIN_H_ | |
| 6 #define CHROME_FRAME_CHROME_FRAME_PLUGIN_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/win/win_util.h" | |
| 13 #include "chrome_frame/chrome_frame_automation.h" | |
| 14 #include "chrome/common/chrome_paths.h" | |
| 15 #include "chrome/common/chrome_paths_internal.h" | |
| 16 #include "chrome_frame/simple_resource_loader.h" | |
| 17 #include "chrome_frame/navigation_constraints.h" | |
| 18 #include "chrome_frame/utils.h" | |
| 19 #include "grit/chromium_strings.h" | |
| 20 | |
| 21 #define IDC_ABOUT_CHROME_FRAME 40018 | |
| 22 | |
| 23 // A class to implement common functionality for all types of | |
| 24 // plugins: ActiveX and ActiveDoc | |
| 25 template <typename T> | |
| 26 class ChromeFramePlugin | |
| 27 : public ChromeFrameDelegateImpl, | |
| 28 public NavigationConstraintsImpl { | |
| 29 public: | |
| 30 ChromeFramePlugin() : ignore_setfocus_(false){ | |
| 31 } | |
| 32 ~ChromeFramePlugin() { | |
| 33 Uninitialize(); | |
| 34 } | |
| 35 | |
| 36 BEGIN_MSG_MAP(T) | |
| 37 MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus) | |
| 38 MESSAGE_HANDLER(WM_PARENTNOTIFY, OnParentNotify) | |
| 39 END_MSG_MAP() | |
| 40 | |
| 41 bool Initialize() { | |
| 42 DVLOG(1) << __FUNCTION__; | |
| 43 DCHECK(!automation_client_.get()); | |
| 44 automation_client_ = CreateAutomationClient(); | |
| 45 if (!automation_client_.get()) { | |
| 46 NOTREACHED() << "new ChromeFrameAutomationClient"; | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 return true; | |
| 51 } | |
| 52 | |
| 53 void Uninitialize() { | |
| 54 DVLOG(1) << __FUNCTION__; | |
| 55 if (IsValid()) { | |
| 56 automation_client_->Uninitialize(); | |
| 57 automation_client_ = NULL; | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 bool InitializeAutomation(const std::wstring& profile_name, | |
| 62 bool incognito, bool is_widget_mode, | |
| 63 const GURL& url, const GURL& referrer, | |
| 64 bool route_all_top_level_navigations) { | |
| 65 DCHECK(IsValid()); | |
| 66 DCHECK(launch_params_ == NULL); | |
| 67 // We don't want to do incognito when privileged, since we're | |
| 68 // running in browser chrome or some other privileged context. | |
| 69 bool incognito_mode = !is_privileged() && incognito; | |
| 70 base::FilePath profile_path; | |
| 71 GetProfilePath(profile_name, &profile_path); | |
| 72 // The profile name could change based on the browser version. For e.g. for | |
| 73 // IE6/7 the profile is created in a different folder whose last component | |
| 74 // is Google Chrome Frame. | |
| 75 base::FilePath actual_profile_name = profile_path.BaseName(); | |
| 76 launch_params_ = new ChromeFrameLaunchParams(url, referrer, profile_path, | |
| 77 actual_profile_name.value(), SimpleResourceLoader::GetLanguage(), | |
| 78 incognito_mode, is_widget_mode, route_all_top_level_navigations); | |
| 79 return automation_client_->Initialize(this, launch_params_); | |
| 80 } | |
| 81 | |
| 82 // ChromeFrameDelegate implementation | |
| 83 virtual WindowType GetWindow() const { | |
| 84 return (static_cast<const T*>(this))->m_hWnd; | |
| 85 } | |
| 86 | |
| 87 virtual void GetBounds(RECT* bounds) { | |
| 88 if (bounds) { | |
| 89 if (::IsWindow(GetWindow())) { | |
| 90 (static_cast<T*>(this))->GetClientRect(bounds); | |
| 91 } | |
| 92 } | |
| 93 } | |
| 94 virtual std::string GetDocumentUrl() { | |
| 95 return document_url_; | |
| 96 } | |
| 97 virtual void OnAutomationServerReady() { | |
| 98 } | |
| 99 | |
| 100 virtual bool IsValid() const { | |
| 101 return automation_client_.get() != NULL; | |
| 102 } | |
| 103 | |
| 104 protected: | |
| 105 LRESULT OnSetFocus(UINT message, WPARAM wparam, LPARAM lparam, | |
| 106 BOOL& handled) { // NO_LINT | |
| 107 return 0; | |
| 108 } | |
| 109 | |
| 110 LRESULT OnParentNotify(UINT message, WPARAM wparam, LPARAM lparam, | |
| 111 BOOL& handled) { // NO_LINT | |
| 112 switch (LOWORD(wparam)) { | |
| 113 case WM_LBUTTONDOWN: | |
| 114 case WM_MBUTTONDOWN: | |
| 115 case WM_RBUTTONDOWN: | |
| 116 case WM_XBUTTONDOWN: { | |
| 117 // If we got activated via mouse click on the external tab, | |
| 118 // we need to update the state of this thread and tell the | |
| 119 // browser that we now have the focus. | |
| 120 HWND focus = ::GetFocus(); | |
| 121 HWND plugin_window = GetWindow(); | |
| 122 | |
| 123 // The Chrome-Frame instance may have launched a popup which currently | |
| 124 // has focus. Because experimental extension popups are top-level | |
| 125 // windows, we have to check that the focus has shifted to a window | |
| 126 // that does not share the same GA_ROOTOWNER as the plugin. | |
| 127 if (focus != plugin_window && | |
| 128 ::GetAncestor(plugin_window, GA_ROOTOWNER) != | |
| 129 ::GetAncestor(focus, GA_ROOTOWNER)) { | |
| 130 ignore_setfocus_ = true; | |
| 131 SetFocus(plugin_window); | |
| 132 ignore_setfocus_ = false; | |
| 133 } | |
| 134 break; | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 return 0; | |
| 139 } | |
| 140 | |
| 141 // Return true if context menu should be displayed. The menu could be | |
| 142 // modified as well (enable/disable commands, add/remove items). | |
| 143 // Override in most-derived class if needed. | |
| 144 bool PreProcessContextMenu(HMENU menu) { | |
| 145 // Add an "About" item. | |
| 146 AppendMenu(menu, MF_STRING, IDC_ABOUT_CHROME_FRAME, | |
| 147 SimpleResourceLoader::Get(IDS_CHROME_FRAME_MENU_ABOUT).c_str()); | |
| 148 return true; | |
| 149 } | |
| 150 | |
| 151 // Allow overriding the type of automation client used, for unit tests. | |
| 152 virtual ChromeFrameAutomationClient* CreateAutomationClient() { | |
| 153 return new ChromeFrameAutomationClient; | |
| 154 } | |
| 155 | |
| 156 virtual void GetProfilePath(const std::wstring& profile_name, | |
| 157 base::FilePath* profile_path) { | |
| 158 return GetChromeFrameProfilePath(profile_name, profile_path); | |
| 159 } | |
| 160 | |
| 161 protected: | |
| 162 // Our gateway to chrome land | |
| 163 scoped_refptr<ChromeFrameAutomationClient> automation_client_; | |
| 164 | |
| 165 // How we launched Chrome. | |
| 166 scoped_refptr<ChromeFrameLaunchParams> launch_params_; | |
| 167 | |
| 168 // Url of the containing document. | |
| 169 std::string document_url_; | |
| 170 | |
| 171 // We set this flag when we're taking the focus ourselves | |
| 172 // and notifying the host browser that we're doing so. | |
| 173 // When the flag is not set, we transfer the focus to chrome. | |
| 174 bool ignore_setfocus_; | |
| 175 }; | |
| 176 | |
| 177 #endif // CHROME_FRAME_CHROME_FRAME_PLUGIN_H_ | |
| OLD | NEW |