Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

150 lines (129 sloc) 4.894 kB
// Copyright (c) 2012 Intel Corp
// Copyright (c) 2012 The Chromium Authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
// pies of the Software, and to permit persons to whom the Software is furnished
// to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in al
// l copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "shell_browser_main_parts.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
#include "content/public/common/url_constants.h"
#include "googleurl/src/gurl.h"
#include "grit/net_resources.h"
#include "net/base/net_module.h"
#include "nw_package.h"
#include "shell.h"
#include "shell_browser_context.h"
#include "shell_devtools_delegate.h"
#include "shell_switches.h"
#include "ui/base/resource/resource_bundle.h"
#if defined(OS_ANDROID)
#include "net/base/network_change_notifier.h"
#include "net/android/network_change_notifier_factory.h"
#endif
namespace content {
namespace {
base::StringPiece PlatformResourceProvider(int key) {
if (key == IDR_DIR_HEADER_HTML) {
base::StringPiece html_data =
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_DIR_HEADER_HTML, ui::SCALE_FACTOR_NONE);
return html_data;
}
return base::StringPiece();
}
} // namespace
ShellBrowserMainParts::ShellBrowserMainParts(
const MainFunctionParams& parameters)
: BrowserMainParts(),
parameters_(parameters),
run_message_loop_(true),
devtools_delegate_(NULL) {
}
ShellBrowserMainParts::~ShellBrowserMainParts() {
}
#if !defined(OS_MACOSX)
void ShellBrowserMainParts::PreMainMessageLoopStart() {
}
#endif
void ShellBrowserMainParts::PostMainMessageLoopStart() {
#if defined(OS_ANDROID)
MessageLoopForUI::current()->Start();
#endif
}
void ShellBrowserMainParts::PreEarlyInitialization() {
#if defined(OS_ANDROID)
net::NetworkChangeNotifier::SetFactory(
new net::android::NetworkChangeNotifierFactory());
#endif
}
void ShellBrowserMainParts::PreMainMessageLoopRun() {
browser_context_.reset(new ShellBrowserContext(false));
off_the_record_browser_context_.reset(new ShellBrowserContext(true));
Shell::PlatformInitialize();
net::NetModule::SetResourceProvider(PlatformResourceProvider);
int port = 0;
// On android the port number isn't used.
#if !defined(OS_ANDROID)
// See if the user specified a port on the command line (useful for
// automation). If not, use an ephemeral port by specifying 0.
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
int temp_port;
std::string port_str =
command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
if (base::StringToInt(port_str, &temp_port) &&
temp_port > 0 && temp_port < 65535) {
port = temp_port;
} else {
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
}
}
#endif
devtools_delegate_ = new ShellDevToolsDelegate(
port, browser_context_->GetRequestContext());
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
Shell::CreateNewWindow(browser_context_.get(),
nw::GetStartupURL(),
NULL,
MSG_ROUTING_NONE,
NULL);
}
if (parameters_.ui_task) {
parameters_.ui_task->Run();
delete parameters_.ui_task;
run_message_loop_ = false;
}
}
bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) {
return !run_message_loop_;
}
void ShellBrowserMainParts::PostMainMessageLoopRun() {
#if defined(USE_AURA)
Shell::PlatformExit();
#endif
if (devtools_delegate_)
devtools_delegate_->Stop();
browser_context_.reset();
off_the_record_browser_context_.reset();
}
} // namespace
Jump to Line
Something went wrong with that request. Please try again.