| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "stdafx.h" | 5 #include "stdafx.h" |
| 6 #include "chrome_url_launch_handler.h" | 6 #include "chrome_url_launch_handler.h" |
| 7 #include "chrome_app_view.h" | 7 #include "chrome_app_view.h" |
| 8 | 8 |
| 9 #include <assert.h> | 9 #include <assert.h> |
| 10 #include <shellapi.h> | 10 #include <shellapi.h> |
| 11 #include <shlobj.h> | 11 #include <shlobj.h> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/string_tokenizer.h" | 14 #include "base/command_line.h" |
| 15 | 15 |
| 16 #include "winrt_utils.h" | 16 #include "winrt_utils.h" |
| 17 | 17 |
| 18 typedef winfoundtn::ITypedEventHandler< | 18 typedef winfoundtn::ITypedEventHandler< |
| 19 winapp::Search::SearchPane*, | 19 winapp::Search::SearchPane*, |
| 20 winapp::Search::SearchPaneQuerySubmittedEventArgs*> QuerySubmittedHandler; | 20 winapp::Search::SearchPaneQuerySubmittedEventArgs*> QuerySubmittedHandler; |
| 21 | 21 |
| 22 ChromeUrlLaunchHandler::ChromeUrlLaunchHandler() { | 22 ChromeUrlLaunchHandler::ChromeUrlLaunchHandler() { |
| 23 globals.is_initial_activation = true; | 23 globals.is_initial_activation = true; |
| 24 globals.initial_activation_kind = winapp::Activation::ActivationKind_Launch; | 24 globals.initial_activation_kind = winapp::Activation::ActivationKind_Launch; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 uri->get_AbsoluteUri(url.GetAddressOf()); | 90 uri->get_AbsoluteUri(url.GetAddressOf()); |
| 91 string16 actual_url(MakeStdWString(url.Get())); | 91 string16 actual_url(MakeStdWString(url.Get())); |
| 92 globals.navigation_url = actual_url; | 92 globals.navigation_url = actual_url; |
| 93 | 93 |
| 94 // If this is the initial activation then we wait for Chrome to initiate the | 94 // If this is the initial activation then we wait for Chrome to initiate the |
| 95 // navigation. In all other cases navigate right away. | 95 // navigation. In all other cases navigate right away. |
| 96 if (!globals.is_initial_activation) | 96 if (!globals.is_initial_activation) |
| 97 InitiateNavigationOrSearchRequest(globals.navigation_url.c_str(), 0); | 97 InitiateNavigationOrSearchRequest(globals.navigation_url.c_str(), 0); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // The LaunchArgs are in a semi-color separated key_name=key_value list. At | 100 // |launch_args| is an encoded command line, minus the executable name. To |
| 101 // the moment the only key_name understaood is "url". | 101 // find the URL to launch the first argument is used. If any other parameters |
| 102 // are encoded in |launch_args| they are ignored. |
| 102 string16 ChromeUrlLaunchHandler::GetUrlFromLaunchArgs( | 103 string16 ChromeUrlLaunchHandler::GetUrlFromLaunchArgs( |
| 103 const string16& launch_args) { | 104 const string16& launch_args) { |
| 104 WStringTokenizer tokenizer(launch_args, L";="); | 105 string16 dummy_command_line(L"dummy.exe "); |
| 105 bool next_is_url = false; | 106 dummy_command_line.append(launch_args); |
| 106 while (tokenizer.GetNext()) { | 107 CommandLine command_line = CommandLine::FromString(dummy_command_line); |
| 107 if (next_is_url) | 108 CommandLine::StringVector args = command_line.GetArgs(); |
| 108 return tokenizer.token(); | 109 if (args.size() > 0) |
| 109 if (tokenizer.token() == L"url") | 110 return args[0]; |
| 110 next_is_url = true; | 111 |
| 111 } | |
| 112 if (launch_args == L"opennewwindow") { | |
| 113 DVLOG(1) << "Returning new tab url"; | |
| 114 return L"chrome://newtab"; | |
| 115 } | |
| 116 return string16(); | 112 return string16(); |
| 117 } | 113 } |
| 118 | 114 |
| 119 void ChromeUrlLaunchHandler::HandleLaunch( | 115 void ChromeUrlLaunchHandler::HandleLaunch( |
| 120 winapp::Activation::ILaunchActivatedEventArgs* args) { | 116 winapp::Activation::ILaunchActivatedEventArgs* args) { |
| 121 mswrw::HString launch_args; | 117 mswrw::HString launch_args; |
| 122 args->get_Arguments(launch_args.GetAddressOf()); | 118 args->get_Arguments(launch_args.GetAddressOf()); |
| 123 string16 actual_launch_args(MakeStdWString(launch_args.Get())); | 119 string16 actual_launch_args(MakeStdWString(launch_args.Get())); |
| 124 globals.navigation_url = GetUrlFromLaunchArgs(actual_launch_args); | 120 globals.navigation_url = GetUrlFromLaunchArgs(actual_launch_args); |
| 125 DVLOG(1) << __FUNCTION__ << ", launch_args=" << actual_launch_args | 121 DVLOG(1) << __FUNCTION__ << ", launch_args=" << actual_launch_args |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 if (url) { | 188 if (url) { |
| 193 VLOG(1) << "Posting url:" << url; | 189 VLOG(1) << "Posting url:" << url; |
| 194 PostMessage(globals.host_windows.front().first, navigation_search_message, | 190 PostMessage(globals.host_windows.front().first, navigation_search_message, |
| 195 reinterpret_cast<WPARAM>(url), 0); | 191 reinterpret_cast<WPARAM>(url), 0); |
| 196 } else { | 192 } else { |
| 197 VLOG(1) << "Posting search string:" << search_string; | 193 VLOG(1) << "Posting search string:" << search_string; |
| 198 PostMessage(globals.host_windows.front().first, navigation_search_message, | 194 PostMessage(globals.host_windows.front().first, navigation_search_message, |
| 199 0, reinterpret_cast<LPARAM>(search_string)); | 195 0, reinterpret_cast<LPARAM>(search_string)); |
| 200 } | 196 } |
| 201 } | 197 } |
| OLD | NEW |