diff options
Diffstat (limited to 'win8')
-rw-r--r-- | win8/metro_driver/chrome_app_view_ash.cc | 95 | ||||
-rw-r--r-- | win8/metro_driver/chrome_app_view_ash.h | 14 | ||||
-rw-r--r-- | win8/viewer/metro_viewer_process_host.cc | 2 | ||||
-rw-r--r-- | win8/viewer/metro_viewer_process_host.h | 9 |
4 files changed, 113 insertions, 7 deletions
diff --git a/win8/metro_driver/chrome_app_view_ash.cc b/win8/metro_driver/chrome_app_view_ash.cc index f3a3a88..8a9e8a1 100644 --- a/win8/metro_driver/chrome_app_view_ash.cc +++ b/win8/metro_driver/chrome_app_view_ash.cc @@ -6,6 +6,7 @@ #include "win8/metro_driver/chrome_app_view_ash.h" #include <corewindow.h> +#include <shellapi.h> #include <windows.foundation.h> #include "base/bind.h" @@ -294,7 +295,9 @@ uint32 GetKeyboardEventFlags() { ChromeAppViewAsh::ChromeAppViewAsh() : mouse_down_flags_(ui::EF_NONE), ui_channel_(nullptr), - core_window_hwnd_(NULL) { + core_window_hwnd_(NULL), + ui_loop_(base::MessageLoop::TYPE_UI) { + DVLOG(1) << __FUNCTION__; globals.previous_state = winapp::Activation::ApplicationExecutionState_NotRunning; } @@ -414,9 +417,6 @@ ChromeAppViewAsh::Run() { return hr; } - // Create a message loop to allow message passing into this thread. - base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI); - // Create the IPC channel IO thread. It needs to out-live the ChannelProxy. base::Thread io_thread("metro_IO_thread"); base::Thread::Options options; @@ -435,7 +435,7 @@ ChromeAppViewAsh::Run() { // In Aura mode we create an IPC channel to the browser, then ask it to // connect to us. - ChromeChannelListener ui_channel_listener(&msg_loop, this); + ChromeChannelListener ui_channel_listener(&ui_loop_, this); IPC::ChannelProxy ui_channel(ipc_channel_name, IPC::Channel::MODE_NAMED_CLIENT, &ui_channel_listener, @@ -449,8 +449,8 @@ ChromeAppViewAsh::Run() { DVLOG(1) << "ICoreWindow sent " << core_window_hwnd_; // And post the task that'll do the inner Metro message pumping to it. - msg_loop.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); - msg_loop.Run(); + ui_loop_.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); + ui_loop_.Run(); DVLOG(0) << "ProcessEvents done, hr=" << hr; return hr; @@ -603,6 +603,18 @@ HRESULT ChromeAppViewAsh::OnActivate( args->get_PreviousExecutionState(&globals.previous_state); DVLOG(1) << "Previous Execution State: " << globals.previous_state; + winapp::Activation::ActivationKind activation_kind; + CheckHR(args->get_Kind(&activation_kind)); + if (activation_kind == winapp::Activation::ActivationKind_Search) + HandleSearchRequest(args); + else if (activation_kind == winapp::Activation::ActivationKind_Protocol) + HandleProtocolRequest(args); + // We call ICoreWindow::Activate after the handling for the search/protocol + // requests because Chrome can be launched to handle a search request which + // in turn launches the chrome browser process in desktop mode via + // ShellExecute. If we call ICoreWindow::Activate before this, then + // Windows kills the metro chrome process when it calls ShellExecute. Seems + // to be a bug. window_->Activate(); return S_OK; } @@ -830,6 +842,75 @@ HRESULT ChromeAppViewAsh::OnWindowActivated( return S_OK; } +HRESULT ChromeAppViewAsh::HandleSearchRequest( + winapp::Activation::IActivatedEventArgs* args) { + mswr::ComPtr<winapp::Activation::ISearchActivatedEventArgs> search_args; + CheckHR(args->QueryInterface( + winapp::Activation::IID_ISearchActivatedEventArgs, &search_args)); + + if (!ui_channel_) { + DVLOG(1) << "Launched to handle search request"; + base::FilePath chrome_exe_path; + + if (!PathService::Get(base::FILE_EXE, &chrome_exe_path)) + return E_FAIL; + + SHELLEXECUTEINFO sei = { sizeof(sei) }; + sei.nShow = SW_SHOWNORMAL; + sei.lpFile = chrome_exe_path.value().c_str(); + sei.lpDirectory = L""; + sei.lpParameters = + L"--silent-launch --viewer-connection=viewer --windows8-search"; + ::ShellExecuteEx(&sei); + } + + mswrw::HString search_string; + CheckHR(search_args->get_QueryText(search_string.GetAddressOf())); + string16 search_text(MakeStdWString(search_string.Get())); + + ui_loop_.PostTask(FROM_HERE, + base::Bind(&ChromeAppViewAsh::OnSearchRequest, + base::Unretained(this), + search_text)); + return S_OK; +} + +HRESULT ChromeAppViewAsh::HandleProtocolRequest( + winapp::Activation::IActivatedEventArgs* args) { + DVLOG(1) << __FUNCTION__; + if (!ui_channel_) + DVLOG(1) << "Launched to handle url request"; + + mswr::ComPtr<winapp::Activation::IProtocolActivatedEventArgs> + protocol_args; + CheckHR(args->QueryInterface( + winapp::Activation::IID_IProtocolActivatedEventArgs, + &protocol_args)); + + mswr::ComPtr<winfoundtn::IUriRuntimeClass> uri; + protocol_args->get_Uri(&uri); + mswrw::HString url; + uri->get_AbsoluteUri(url.GetAddressOf()); + string16 actual_url(MakeStdWString(url.Get())); + DVLOG(1) << "Received url request: " << actual_url; + + ui_loop_.PostTask(FROM_HERE, + base::Bind(&ChromeAppViewAsh::OnNavigateToUrl, + base::Unretained(this), + actual_url)); + return S_OK; +} + +void ChromeAppViewAsh::OnSearchRequest(const string16& search_string) { + DCHECK(ui_channel_); + ui_channel_->Send(new MetroViewerHostMsg_SearchRequest(search_string)); +} + +void ChromeAppViewAsh::OnNavigateToUrl(const string16& url) { + DCHECK(ui_channel_); + ui_channel_->Send(new MetroViewerHostMsg_OpenURL(url)); +} + /////////////////////////////////////////////////////////////////////////////// diff --git a/win8/metro_driver/chrome_app_view_ash.h b/win8/metro_driver/chrome_app_view_ash.h index 0989cda..35c283e 100644 --- a/win8/metro_driver/chrome_app_view_ash.h +++ b/win8/metro_driver/chrome_app_view_ash.h @@ -12,6 +12,7 @@ #include "base/files/file_path.h" #include "base/memory/scoped_ptr.h" +#include "base/message_loop.h" #include "base/string16.h" #include "ui/base/events/event_constants.h" #include "win8/metro_driver/direct3d_helper.h" @@ -111,6 +112,16 @@ class ChromeAppViewAsh HRESULT OnWindowActivated(winui::Core::ICoreWindow* sender, winui::Core::IWindowActivatedEventArgs* args); + // Helper to handle search requests received via the search charm in ASH. + HRESULT HandleSearchRequest(winapp::Activation::IActivatedEventArgs* args); + // Helper to handle http/https url requests in ASH. + HRESULT HandleProtocolRequest(winapp::Activation::IActivatedEventArgs* args); + + // Tasks posted to the UI thread to initiate the search/url navigation + // requests. + void OnSearchRequest(const string16& search_string); + void OnNavigateToUrl(const string16& url); + mswr::ComPtr<winui::Core::ICoreWindow> window_; mswr::ComPtr<winapp::Core::ICoreApplicationView> view_; EventRegistrationToken activated_token_; @@ -138,6 +149,9 @@ class ChromeAppViewAsh // The actual window behind the view surface. HWND core_window_hwnd_; + + // UI message loop to allow message passing into this thread. + base::MessageLoop ui_loop_; }; #endif // WIN8_METRO_DRIVER_CHROME_APP_VIEW_ASH_H_ diff --git a/win8/viewer/metro_viewer_process_host.cc b/win8/viewer/metro_viewer_process_host.cc index f945039..0e4c535 100644 --- a/win8/viewer/metro_viewer_process_host.cc +++ b/win8/viewer/metro_viewer_process_host.cc @@ -94,6 +94,8 @@ bool MetroViewerProcessHost::OnMessageReceived( bool handled = true; IPC_BEGIN_MESSAGE_MAP(MetroViewerProcessHost, message) IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetTargetSurface, OnSetTargetSurface) + IPC_MESSAGE_HANDLER(MetroViewerHostMsg_OpenURL, OnOpenURL) + IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SearchRequest, OnHandleSearchRequest) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled ? true : diff --git a/win8/viewer/metro_viewer_process_host.h b/win8/viewer/metro_viewer_process_host.h index b9c3e77..5dfa5d3 100644 --- a/win8/viewer/metro_viewer_process_host.h +++ b/win8/viewer/metro_viewer_process_host.h @@ -65,6 +65,15 @@ class MetroViewerProcessHost : public IPC::Listener, // drawing to |target_surface|. virtual void OnSetTargetSurface(gfx::NativeViewId target_surface) = 0; + // Called over IPC by the viewer process to request that the url passed in be + // opened. + virtual void OnOpenURL(const string16& url) = 0; + + // Called over IPC by the viewer process to request that the search string + // passed in is passed to the default search provider and a URL navigation be + // performed. + virtual void OnHandleSearchRequest(const string16& search_string) = 0; + void NotifyChannelConnected(); // Inner message filter used to handle connection event on the IPC channel |