Skip to content

Commit

Permalink
Register browser. It is possible to register via "nw.App.registerBrow…
Browse files Browse the repository at this point in the history
…ser" function (changes in chromium project '\src\content\nw' as well).
  • Loading branch information
janRucka committed Jan 25, 2017
1 parent d7bcfde commit 43ab7bc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
19 changes: 19 additions & 0 deletions chrome/browser/shell_integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ void DefaultWebClientWorker::StartSetAsDefault() {
base::Bind(&DefaultWebClientWorker::SetAsDefault, this));
}

void DefaultWebClientWorker::StartRegistration() {
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&DefaultWebClientWorker::Registration, this));
}

///////////////////////////////////////////////////////////////////////////////
// DefaultWebClientWorker, protected:

Expand Down Expand Up @@ -179,6 +185,14 @@ void DefaultWebClientWorker::CheckIsDefault(bool is_following_set_as_default) {
is_following_set_as_default));
}

void DefaultWebClientWorker::IsRegistered(bool registered) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
DefaultWebClientState state = registered ? DefaultWebClientState::IS_DEFAULT : DefaultWebClientState::NOT_DEFAULT;
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state, false));
}

void DefaultWebClientWorker::SetAsDefault() {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);

Expand All @@ -187,6 +201,11 @@ void DefaultWebClientWorker::SetAsDefault() {
base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, true));
}

void DefaultWebClientWorker::Registration() {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
Register(base::Bind(&DefaultWebClientWorker::IsRegistered, this));
}

void DefaultWebClientWorker::ReportSetDefaultResult(
DefaultWebClientState state) {
base::LinearHistogram::FactoryGet(
Expand Down
11 changes: 11 additions & 0 deletions chrome/browser/shell_integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ namespace shell_integration {
// Prefer to use the DefaultBrowserWorker class below since it works on all OSs.
bool SetAsDefaultBrowser();


bool Register(base::Callback<void(bool)> callback);

// Sets Chrome as the default client application for the given protocol
// (only for the current user). Returns false if this operation fails.
// Prefer to use the DefaultProtocolClientWorker class below since it works on
Expand Down Expand Up @@ -156,6 +159,9 @@ class DefaultWebClientWorker
// the default state to the caller.
void StartSetAsDefault();

// Register app as able to handle default files (e.g. *.htm, *.pdf)
void StartRegistration();

protected:
friend class base::RefCountedThreadSafe<DefaultWebClientWorker>;

Expand All @@ -179,9 +185,14 @@ class DefaultWebClientWorker
// will be reported to UMA as the result of the set-as-default operation.
void CheckIsDefault(bool is_following_set_as_default);

void IsRegistered(bool registered);

// Sets Chrome as the default web client. Always called on the FILE thread.
void SetAsDefault();

// Register app as able to handle default files (e.g. *.htm, *.pdf)
void Registration();

// Implementation of CheckIsDefault() and SetAsDefault() for subclasses.
virtual DefaultWebClientState CheckIsDefaultImpl() = 0;

Expand Down
16 changes: 16 additions & 0 deletions chrome/browser/shell_integration_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,22 @@ bool SetAsDefaultProtocolClient(const std::string& protocol) {
return true;
}

bool Register(base::Callback<void(bool)> callback)
{
base::FilePath chrome_exe;
if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
LOG(ERROR) << "Error getting app exe path";
callback.Run(false);
return false;
}

BrowserDistribution* dist = BrowserDistribution::GetDistribution();
bool retVal = ShellUtil::RegisterChromeBrowser(dist, chrome_exe, base::string16(), true);

callback.Run(retVal);
return retVal;
}

DefaultWebClientSetPermission GetDefaultWebClientSetPermission() {
BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
if (distribution->GetDefaultBrowserControlPolicy() !=
Expand Down
2 changes: 1 addition & 1 deletion chrome/installer/util/shell_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ const wchar_t* ShellUtil::kAppPathsRegistryPathName = L"Path";
const wchar_t* ShellUtil::kDefaultFileAssociations[] = {L".htm", L".html",
L".shtml", L".xht", L".xhtml", NULL};
const wchar_t* ShellUtil::kPotentialFileAssociations[] = {L".htm", L".html",
L".shtml", L".xht", L".xhtml", L".webp", NULL};
L".pdf", L".shtml", L".xht", L".xhtml", L".webp", NULL};
const wchar_t* ShellUtil::kBrowserProtocolAssociations[] = {L"ftp", L"http",
L"https", NULL};
const wchar_t* ShellUtil::kPotentialProtocolAssociations[] = {L"ftp", L"http",
Expand Down

0 comments on commit 43ab7bc

Please sign in to comment.