blob: 9642c6ed64734be630493c0ab84697bbaa391097 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright (c) 2012 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/ui/startup/startup_browser_creator_win.h"
#include "base/logging.h"
#include "base/win/metro.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
namespace browser {
// Metro driver exports for getting the launch type, initial url, initial
// search term, etc.
extern "C" {
typedef const wchar_t* (*GetInitialUrl)();
typedef const wchar_t* (*GetInitialSearchString)();
typedef base::win::MetroLaunchType (*GetLaunchType)(
base::win::MetroPreviousExecutionState* previous_state);
}
GURL GetURLToOpen(Profile* profile) {
HMODULE metro = base::win::GetMetroModule();
if (!metro)
return GURL();
GetLaunchType get_launch_type = reinterpret_cast<GetLaunchType>(
::GetProcAddress(metro, "GetLaunchType"));
DCHECK(get_launch_type);
base::win::MetroLaunchType launch_type = get_launch_type(NULL);
if (launch_type == base::win::PROTOCOL || launch_type == base::win::LAUNCH) {
GetInitialUrl initial_metro_url = reinterpret_cast<GetInitialUrl>(
::GetProcAddress(metro, "GetInitialUrl"));
DCHECK(initial_metro_url);
const wchar_t* initial_url = initial_metro_url();
if (initial_url)
return GURL(initial_url);
} else if (launch_type == base::win::SEARCH) {
GetInitialSearchString initial_search_string =
reinterpret_cast<GetInitialSearchString>(
::GetProcAddress(metro, "GetInitialSearchString"));
DCHECK(initial_search_string);
string16 search_string = initial_search_string();
const TemplateURL* default_provider =
TemplateURLServiceFactory::GetForProfile(profile)->
GetDefaultSearchProvider();
if (default_provider) {
const TemplateURLRef& search_url = default_provider->url_ref();
DCHECK(search_url.SupportsReplacement());
return GURL(search_url.ReplaceSearchTerms(search_string,
TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
}
}
return GURL();
}
} // namespace browser
|