[M108 Migration][VD] Implement Multi port RWI 13/289413/9
authorjiangyuwei <yuwei.jiang@samsung.com>
Tue, 7 Mar 2023 09:02:13 +0000 (17:02 +0800)
committerjiang yuwei <yuwei.jiang@samsung.com>
Thu, 9 Mar 2023 00:53:56 +0000 (00:53 +0000)
RWI server can use easily to debug application.
Multi port RWI can let 3 applications debug at the same time.
Normal RWI server should start when WebContents init.
For RELEASE_MODE shuold use ewk_view_inspector_server_start
to start RWI server.

Reference:
  - https://review.tizen.org/gerrit/279379/
  - https://review.tizen.org/gerrit/281862/

Change-Id: I9dd2be6d0d59c390bb271d004e67b9add29df546
Signed-off-by: jiangyuwei <yuwei.jiang@samsung.com>
39 files changed:
content/browser/BUILD.gn
content/browser/devtools/devtools_http_handler.cc
content/browser/devtools/devtools_http_handler.h
content/browser/devtools/devtools_video_consumer.cc
content/browser/web_contents/web_contents_impl.cc
content/public/browser/devtools_manager_delegate.cc
content/public/browser/devtools_manager_delegate.h
content/public/browser/javascript_dialog_manager.h
tizen_src/chromium_impl/content/browser/browser_efl.gni
tizen_src/chromium_impl/content/browser/inspector/devtools_util_manager.cc [new file with mode: 0644]
tizen_src/chromium_impl/content/browser/inspector/devtools_util_manager.h [new file with mode: 0644]
tizen_src/ewk/efl_integration/BUILD.gn
tizen_src/ewk/efl_integration/browser/javascript_dialog_manager_efl.cc
tizen_src/ewk/efl_integration/browser/javascript_dialog_manager_efl.h
tizen_src/ewk/efl_integration/browser_main_parts_efl.cc
tizen_src/ewk/efl_integration/common/content_client_efl.cc
tizen_src/ewk/efl_integration/content_browser_client_efl.cc
tizen_src/ewk/efl_integration/content_browser_client_efl.h
tizen_src/ewk/efl_integration/content_main_delegate_efl.cc
tizen_src/ewk/efl_integration/content_main_delegate_efl.h
tizen_src/ewk/efl_integration/devtools_delegate_efl.cc
tizen_src/ewk/efl_integration/devtools_delegate_efl.h
tizen_src/ewk/efl_integration/devtools_port_manager.cc [new file with mode: 0644]
tizen_src/ewk/efl_integration/devtools_port_manager.h [new file with mode: 0644]
tizen_src/ewk/efl_integration/devtools_port_msg.cc [new file with mode: 0644]
tizen_src/ewk/efl_integration/devtools_port_msg.h [new file with mode: 0644]
tizen_src/ewk/efl_integration/devtools_port_shared_memory.cc [new file with mode: 0644]
tizen_src/ewk/efl_integration/devtools_port_shared_memory.h [new file with mode: 0644]
tizen_src/ewk/efl_integration/eweb_context.cc
tizen_src/ewk/efl_integration/eweb_context.h
tizen_src/ewk/efl_integration/eweb_view.cc
tizen_src/ewk/efl_integration/eweb_view.h
tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc
tizen_src/ewk/efl_integration/web_contents_delegate_efl.h
tizen_src/ewk/efl_integration/web_contents_observer_efl.cc
wrt/src/browser/api/tv/wrt_api_tv_extension.cc
wrt/src/browser/api/wrt_api_web_runtime.cc
wrt/src/browser/wrt_devtools_manager_delegate.cc
wrt/src/browser/wrt_devtools_manager_delegate.h

index cb36b60..d3c3c0c 100644 (file)
@@ -59,6 +59,7 @@ source_set("browser") {
   frameworks = []
   ldflags = []
 
+  include_dirs = [ "//tizen_src/ewk/efl_integration/" ]
   if (use_efl) {
     configs += external_content_browser_efl_configs
   }
index 286e99d..cb0697e 100644 (file)
@@ -143,6 +143,10 @@ class ServerWrapper : net::HttpServer::Delegate {
   void Send500(int connection_id, const std::string& message);
   void Close(int connection_id);
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  base::WeakPtr<DevToolsHttpHandler> GetHttpHandle() { return handler_; }
+#endif
+
   ~ServerWrapper() override {}
 
  private:
@@ -220,10 +224,25 @@ void TerminateOnUI(std::unique_ptr<base::Thread> thread,
                    std::unique_ptr<ServerWrapper> server_wrapper,
                    std::unique_ptr<DevToolsSocketFactory> socket_factory) {
   DCHECK_CURRENTLY_ON(BrowserThread::UI);
-  if (server_wrapper)
+#if BUILDFLAG(IS_TIZEN_TV)
+  base::WeakPtr<DevToolsHttpHandler> handler;
+#endif
+  if (server_wrapper) {
+#if BUILDFLAG(IS_TIZEN_TV)
+    handler = server_wrapper->GetHttpHandle();
+#endif
     thread->task_runner()->DeleteSoon(FROM_HERE, std::move(server_wrapper));
-  if (socket_factory)
+  }
+  if (socket_factory) {
     thread->task_runner()->DeleteSoon(FROM_HERE, std::move(socket_factory));
+#if BUILDFLAG(IS_TIZEN_TV)
+    if (handler) {
+      thread->task_runner()->PostTask(
+          FROM_HERE,
+          base::BindOnce(&DevToolsHttpHandler::ReleasePort, handler));
+    }
+#endif
+  }
   if (thread) {
     base::ThreadPool::PostTask(
         FROM_HERE,
@@ -438,7 +457,15 @@ void ServerWrapper::OnHttpRequest(int connection_id,
   }
 
   server_->SetSendBufferSize(connection_id, kSendBufferSizeForDevTools);
-
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (info.path.find("/closeport") == 0) {
+    // close first listened port
+    GetUIThreadTaskRunner({})->PostTask(
+        FROM_HERE, base::BindOnce(&DevToolsHttpHandler::OnTerminateSocket,
+                                  handler_, connection_id));
+    return;
+  }
+#endif
   if (base::StartsWith(info.path, "/json", base::CompareCase::SENSITIVE)) {
     GetUIThreadTaskRunner({})->PostTask(
         FROM_HERE, base::BindOnce(&DevToolsHttpHandler::OnJsonRequest, handler_,
@@ -547,6 +574,18 @@ static bool ParseJsonPath(
   return true;
 }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+void DevToolsHttpHandler::OnTerminateSocket(int connection_id) {
+  server_wrapper_->Send200(connection_id, "OK", "text/html");
+  TerminateOnUI(std::move(thread_), std::move(server_wrapper_),
+                std::move(socket_factory_));
+}
+
+void DevToolsHttpHandler::ReleasePort() {
+  delegate_->ReleasePort();
+}
+#endif
+
 // These values are persisted to logs. Entries should not be renumbered and
 // numeric values should never be reused.
 enum class DevToolsMutatingHttpActionVerb {
index 04a4905..cd8710e 100644 (file)
@@ -56,6 +56,10 @@ class DevToolsHttpHandler {
 
   ~DevToolsHttpHandler();
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  void ReleasePort();
+#endif
+
  private:
   friend class ServerWrapper;
   friend void ServerStartedOnUI(
@@ -65,6 +69,10 @@ class DevToolsHttpHandler {
       DevToolsSocketFactory* socket_factory,
       std::unique_ptr<net::IPEndPoint> ip_address);
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  void OnTerminateSocket(int connection_id);
+#endif
+
   void OnJsonRequest(int connection_id,
                      const net::HttpServerRequestInfo& info);
   void RespondToJsonList(int connection_id,
index a803636..835d7b7 100644 (file)
@@ -11,6 +11,7 @@
 #include "cc/paint/skia_paint_canvas.h"
 #include "components/viz/common/surfaces/subtree_capture_id.h"
 #include "components/viz/host/host_frame_sink_manager.h"
+#include "components/viz/service/frame_sinks/video_capture/frame_sink_video_capturer_impl.h"
 #include "content/browser/compositor/surface_utils.h"
 #include "media/base/limits.h"
 #include "media/capture/mojom/video_capture_buffer.mojom.h"
@@ -35,7 +36,10 @@ constexpr media::VideoPixelFormat kDefaultPixelFormat =
 
 // Creates a ClientFrameSinkVideoCapturer via HostFrameSinkManager.
 std::unique_ptr<viz::ClientFrameSinkVideoCapturer> CreateCapturer() {
-  return GetHostFrameSinkManager()->CreateVideoCapturer();
+  if (GetHostFrameSinkManager())
+    return GetHostFrameSinkManager()->CreateVideoCapturer();
+  else
+    return nullptr;
 }
 
 }  // namespace
@@ -115,7 +119,8 @@ void DevToolsVideoConsumer::SetFormat(media::VideoPixelFormat format) {
 void DevToolsVideoConsumer::InnerStartCapture(
     std::unique_ptr<viz::ClientFrameSinkVideoCapturer> capturer) {
   capturer_ = std::move(capturer);
-
+  if (!capturer_)
+    return;
   // Give |capturer_| the capture parameters.
   capturer_->SetMinCapturePeriod(min_capture_period_);
   capturer_->SetMinSizeChangePeriod(kDefaultMinPeriod);
index b8dbef7..5a50360 100644 (file)
@@ -8438,6 +8438,11 @@ void WebContentsImpl::OnDialogClosed(int render_process_id,
   for (auto* handler : page_handlers)
     handler->DidCloseJavaScriptDialog(success, user_input);
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (dialog_manager_)
+    dialog_manager_->OnDialogClosed(this);
+#endif
+
   is_showing_javascript_dialog_ = false;
   is_showing_before_unload_dialog_ = false;
 }
index 70900b1..30d31f5 100644 (file)
@@ -70,6 +70,11 @@ std::string DevToolsManagerDelegate::GetDiscoveryPageHTML() {
   return std::string();
 }
 
+std::string DevToolsManagerDelegate::GetFrontendResource(
+    const std::string& path) {
+  return std::string();
+}
+
 bool DevToolsManagerDelegate::HasBundledFrontendResources() {
   return false;
 }
index cdd9888..facfa79 100644 (file)
@@ -75,7 +75,7 @@ class CONTENT_EXPORT DevToolsManagerDelegate {
   // Should return discovery page HTML that should list available tabs
   // and provide attach links.
   virtual std::string GetDiscoveryPageHTML();
-
+  virtual std::string GetFrontendResource(const std::string& path);
   // Returns whether frontend resources are bundled within the binary.
   virtual bool HasBundledFrontendResources();
 
@@ -89,6 +89,10 @@ class CONTENT_EXPORT DevToolsManagerDelegate {
   virtual bool IsBrowserTargetDiscoverable();
 
   virtual ~DevToolsManagerDelegate();
+
+#if BUILDFLAG(IS_TIZEN_TV)
+  virtual void ReleasePort() {}
+#endif
 };
 
 }  // namespace content
index bb0abaf..7449c64 100644 (file)
@@ -55,6 +55,10 @@ class CONTENT_EXPORT JavaScriptDialogManager {
   virtual void CancelDialogs(WebContents* web_contents,
                              bool reset_state) = 0;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  virtual void OnDialogClosed(WebContents* web_contents) {}
+#endif
+
   virtual ~JavaScriptDialogManager() {}
 };
 
index 03a1545..158df51 100644 (file)
@@ -118,6 +118,8 @@ external_content_browser_efl_sources = [
   "//tizen_src/chromium_impl/content/browser/web_contents/web_drag_dest_efl.h",
   "//tizen_src/chromium_impl/content/browser/web_contents/web_drag_source_efl.cc",
   "//tizen_src/chromium_impl/content/browser/web_contents/web_drag_source_efl.h",
+  "//tizen_src/chromium_impl/content/browser/inspector/devtools_util_manager.cc",
+  "//tizen_src/chromium_impl/content/browser/inspector/devtools_util_manager.h",
 ]
 
 external_content_browser_efl_sources += [
diff --git a/tizen_src/chromium_impl/content/browser/inspector/devtools_util_manager.cc b/tizen_src/chromium_impl/content/browser/inspector/devtools_util_manager.cc
new file mode 100644 (file)
index 0000000..9211312
--- /dev/null
@@ -0,0 +1,172 @@
+// Copyright 2020 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "devtools_util_manager.h"
+
+#include "base/command_line.h"
+#include "base/strings/string_number_conversions.h"
+#include "content/public/browser/devtools_agent_host.h"
+#include "content/public/browser/devtools_frontend_host.h"
+#include "content/public/browser/devtools_socket_factory.h"
+#include "content/public/common/content_switches.h"
+#include "net/base/net_errors.h"
+#include "net/socket/tcp_server_socket.h"
+#include "third_party/zlib/google/compression_utils.h"
+
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "devtools_port_manager.h"
+#endif
+
+using content::DevToolsAgentHost;
+
+namespace content {
+
+// Copy of internal class implementation from
+// content/shell/browser/shell_devtools_delegate.cc
+
+const int kBackLog = 10;
+
+class TCPServerSocketFactory : public content::DevToolsSocketFactory {
+ public:
+  TCPServerSocketFactory(const std::string& address, uint16_t port)
+      : server_socket_(nullptr), address_(address), port_(port) {}
+  TCPServerSocketFactory(std::unique_ptr<net::ServerSocket> server_socket)
+      : server_socket_(server_socket.release()), port_(0) {}
+
+ private:
+  std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
+    if (server_socket_)
+      return std::unique_ptr<net::ServerSocket>(server_socket_);
+    std::unique_ptr<net::ServerSocket> socket(
+        new net::TCPServerSocket(nullptr, net::NetLogSource()));
+    if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK)
+      return std::unique_ptr<net::ServerSocket>();
+
+    return socket;
+  }
+
+  std::unique_ptr<net::ServerSocket> CreateForTethering(
+      std::string* out_name) override {
+    return nullptr;
+  }
+
+  net::ServerSocket* server_socket_;
+  std::string address_;
+  uint16_t port_;
+};
+
+// static
+uint16_t DevToolsUtilManager::port_ = 0;
+
+DevToolsUtilManager::DevToolsUtilManager() = default;
+DevToolsUtilManager::~DevToolsUtilManager() = default;
+
+DevToolsUtilManager* DevToolsUtilManager::GetInstance() {
+  static DevToolsUtilManager instance;
+  return &instance;
+}
+
+int DevToolsUtilManager::StartDebugServer(int port) {
+  if (port_ > 0)
+    return port_;
+
+  // It's a hacky way to early detected if port is available. The problem is
+  // that the only thing we can do after checking is hope that noone will take
+  // the port until it's initialized on IO thread again. The best approach would
+  // be creating async callbacks that would inform when inspector server started
+  // and on which port.
+  static std::string addr = "0.0.0.0";
+  std::unique_ptr<net::ServerSocket> sock(
+      new net::TCPServerSocket(nullptr, net::NetLogSource()));
+
+  const base::CommandLine* const command_line =
+      base::CommandLine::ForCurrentProcess();
+  // See if the user specified a port on the command line (useful for
+  // automation). If not, use an ephemeral port by specifying 0.
+  if (!port && command_line->HasSwitch(switches::kRemoteDebuggingPort)) {
+    int temp_port = 0;
+    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 {
+      LOG(WARNING) << "Invalid http debugger port number " << temp_port;
+    }
+  }
+
+  // why backlog is 1?
+  if (sock->ListenWithAddressAndPort(addr, port, 1) != net::OK) {
+    port_ = 0;
+#if BUILDFLAG(IS_TIZEN_TV)
+    ReleasePort();
+#endif
+    return port_;
+  }
+
+  net::IPEndPoint givenIp;
+  sock->GetLocalAddress(&givenIp);
+  port_ = givenIp.port();
+  LOG(INFO) << "Devtool port:" << port_;
+
+  std::unique_ptr<content::DevToolsSocketFactory> factory(
+      new TCPServerSocketFactory(std::move(sock)));
+  DevToolsAgentHost::StartRemoteDebuggingServer(
+      std::move(factory), base::FilePath(), base::FilePath());
+
+  return port_;
+}
+
+bool DevToolsUtilManager::StopDebugServer() {
+  if (port_ == 0)
+    return false;
+  port_ = 0;
+  DevToolsAgentHost::StopRemoteDebuggingServer();
+  return true;
+}
+
+unsigned int DevToolsUtilManager::InspectorServerStart(int port) {
+  InspectorServerStop();
+#if BUILDFLAG(IS_TIZEN_TV)
+  devtools_http_handler::DevToolsPortManager* port_manager =
+      devtools_http_handler::DevToolsPortManager::GetInstance();
+  if (!port && (port_manager && port_manager->ProcessCompare())) {
+    if (port_manager->GetValidPort(port))
+      port_manager->SetPort(port);
+  }
+#endif
+  return StartDebugServer(port);
+}
+
+bool DevToolsUtilManager::InspectorServerStop() {
+  if (!StopDebugServer())
+    return false;
+#if BUILDFLAG(IS_TIZEN_TV)
+  ReleasePort();
+#endif
+  return true;
+}
+
+std::string DevToolsUtilManager::GetFrontendResource(const std::string& path) {
+  const std::string data =
+      content::DevToolsFrontendHost::GetFrontendResource(path);
+  // Detect gzip resource with the gzip magic number(1f 8b) in header
+  if (data.length() > 2 && data[0] == '\x1F' && data[1] == '\x8B') {
+    std::string uncompressed_data;
+
+    if (compression::GzipUncompress(data, &uncompressed_data))
+      return uncompressed_data;
+    LOG(ERROR) << "Failed to uncompress " << path;
+  }
+  return data;
+}
+
+#if BUILDFLAG(IS_TIZEN_TV)
+void DevToolsUtilManager::ReleasePort() {
+  if (devtools_http_handler::DevToolsPortManager::GetInstance())
+    devtools_http_handler::DevToolsPortManager::GetInstance()->ReleasePort();
+}
+#endif
+
+}  // namespace content
diff --git a/tizen_src/chromium_impl/content/browser/inspector/devtools_util_manager.h b/tizen_src/chromium_impl/content/browser/inspector/devtools_util_manager.h
new file mode 100644 (file)
index 0000000..77e9f52
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright 2020 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVTOOLS_UTIL_MANAGER_H_
+#define DEVTOOLS_UTIL_MANAGER_H_
+
+#include <string>
+#include "build/buildflag.h"
+#include "build/build_config.h"
+
+namespace content {
+
+class DevToolsUtilManager {
+ public:
+  DevToolsUtilManager();
+  virtual ~DevToolsUtilManager();
+
+  static DevToolsUtilManager* GetInstance();
+
+  unsigned int InspectorServerStart(int port = 0);
+  bool InspectorServerStop();
+
+  std::string GetFrontendResource(const std::string& path);
+
+#if BUILDFLAG(IS_TIZEN_TV)
+  static uint16_t GetPort() { return port_; }
+  void ReleasePort();
+#endif
+
+ private:
+  int StartDebugServer(int port);
+  bool StopDebugServer();
+
+  static uint16_t port_;
+};
+
+}  // namespace content
+
+#endif  // DEVTOOLS_UTIL_MANAGER_H_
index 33fac56..87210fc 100755 (executable)
@@ -650,6 +650,12 @@ shared_library("chromium-ewk") {
       "wrt/hbbtv_widget.h",
       "wrt/hbbtv_widget_host.cc",
       "wrt/hbbtv_widget_host.h",
+      "devtools_port_manager.cc",
+      "devtools_port_manager.h",
+      "devtools_port_msg.cc",
+      "devtools_port_msg.h",
+      "devtools_port_shared_memory.cc",
+      "devtools_port_shared_memory.h",
     ]
   }
 
index 3a5b308..6b00fc3 100644 (file)
@@ -112,6 +112,15 @@ void JavaScriptDialogManagerEfl::SetPopupSize(int width, int height) {
     dialog_->SetPopupSize(width, height);
 }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+void JavaScriptDialogManagerEfl::OnDialogClosed(
+    content::WebContents* web_contents) {
+  EWebView* wv = WebViewFromWebContents(web_contents);
+  if (wv)
+    wv->OnDialogClosed();
+}
+#endif
+
 void JavaScriptDialogManagerEfl::RunBeforeUnloadDialog(
     content::WebContents* web_contents,
     content::RenderFrameHost* render_frame_host,
index 9524650..b37f81e 100644 (file)
@@ -52,6 +52,9 @@ class JavaScriptDialogManagerEfl : public content::JavaScriptDialogManager {
                          void* user_data);
   void ExecuteDialogClosedCallBack(bool result, const std::string prompt_data);
   void SetPopupSize(int width, int height);
+#if BUILDFLAG(IS_TIZEN_TV)
+  void OnDialogClosed(content::WebContents* web_contents) override;
+#endif
   void SetBeforeUnloadConfirmPanelCallback(
       Ewk_View_Before_Unload_Confirm_Panel_Callback callback,
       void* user_data);
index a95d634..892d028 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "base/base_switches.h"
 #include "base/command_line.h"
+#include "content/browser/inspector/devtools_util_manager.h"
 #include "content/public/common/content_switches.h"
 #include "content/public/common/result_codes.h"
 
@@ -32,8 +33,7 @@ int BrowserMainPartsEfl::PreMainMessageLoopRun() {
 }
 
 void BrowserMainPartsEfl::PostMainMessageLoopRun() {
-  if (devtools_delegate_)
-    devtools_delegate_->Stop();
+  DevToolsUtilManager::GetInstance()->InspectorServerStop();
 }
 
 }  // namespace
index ddf0186..7dd5a2d 100644 (file)
@@ -5,8 +5,8 @@
 #include "common/content_client_efl.h"
 
 #include "ipc/ipc_message.h"
-#include "ui/base/resource/resource_bundle.h"
 #include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
 
 std::u16string ContentClientEfl::GetLocalizedString(int message_id) {
   // TODO(boliu): Used only by WebKit, so only bundle those resources for
index e40da0e..58b9c64 100644 (file)
@@ -443,10 +443,12 @@ void ContentBrowserClientEfl::RenderProcessWillLaunch(
   host->AddFilter(new RenderMessageFilterEfl(host->GetID()));
 }
 
-content::DevToolsManagerDelegate*
-ContentBrowserClientEfl::GetDevToolsManagerDelegate() {
-  return new DevToolsManagerDelegateEfl();
+/* LCOV_EXCL_START */
+std::unique_ptr<content::DevToolsManagerDelegate>
+ContentBrowserClientEfl::CreateDevToolsManagerDelegate() {
+  return std::make_unique<DevToolsDelegateEfl>();
 }
+/* LCOV_EXCL_STOP */
 
 std::string ContentBrowserClientEfl::GetApplicationLocale() {
   char* local_default = setlocale(LC_CTYPE, 0);
index d783485..5c480fc 100644 (file)
@@ -110,6 +110,8 @@ class ContentBrowserClientEfl : public ContentBrowserClient {
                            blink::web_pref::WebPreferences* prefs);
   void RenderProcessWillLaunch(RenderProcessHost* host) override;
   DevToolsManagerDelegate* GetDevToolsManagerDelegate();
+  std::unique_ptr<content::DevToolsManagerDelegate>
+  CreateDevToolsManagerDelegate() override;
   std::string GetApplicationLocale() override;
   std::unique_ptr<WebContentsViewDelegate> GetWebContentsViewDelegate(
       WebContents* web_contents) override;
index 8ee2f48..d69d015 100644 (file)
 #include "content_browser_client_efl.h"
 #include "renderer/content_renderer_client_efl.h"
 #include "ui/base/resource/resource_bundle.h"
-
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "content/public/browser/render_process_host.h"
+#include "devtools_port_manager.h"
+#endif
 namespace content {
 
 namespace {
@@ -65,6 +68,13 @@ void InitializeDiskCacheDir() {
 }
 } // namespace
 
+ContentMainDelegateEfl::ContentMainDelegateEfl() {
+#if BUILDFLAG(IS_TIZEN_TV)
+  enableInspector_ = false;
+#endif
+}
+
+
 void ContentMainDelegateEfl::PreSandboxStartupBrowser() {
   LocaleEfl::Initialize();
   base::PathService::Override(base::FILE_EXE, base::FilePath(SubProcessPath()));
@@ -118,4 +128,32 @@ ContentBrowserClient* ContentMainDelegateEfl::GetContentBrowserClient() const {
   return browser_client_.get();
 }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+void ContentMainDelegateEfl::ProcessExiting(const std::string& process_type) {
+  if (!enableInspector_)
+    return;
+
+  if (process_type.empty() &&
+      devtools_http_handler::DevToolsPortManager::GetInstance())  // browser
+    devtools_http_handler::DevToolsPortManager::GetInstance()->ReleasePort();
+}
+
+void ContentMainDelegateEfl::SetInspectorStatus(bool enable) {
+  enableInspector_ = enable;
+}
+
+bool ContentMainDelegateEfl::GetInspectorStatus() {
+  return enableInspector_;
+}
+
+ContentMainDelegateEfl::~ContentMainDelegateEfl() {
+  if (content::RenderProcessHost::run_renderer_in_process()) {
+    LOG(INFO) << "ContentMainDelegateEfl[" << (void*)this
+              << "]::~ContentMainDelegateEfl, set ContentClient to nullptr";
+    content::SetContentClient(nullptr);
+  }
+}
+#endif
+
+
 } // namespace content
index 470710f..f7697ea 100644 (file)
@@ -17,8 +17,10 @@ namespace content {
 class ContentMainDelegateEfl
     : public ContentMainDelegate {
  public:
-  ContentMainDelegateEfl() = default;
-  ~ContentMainDelegateEfl() override = default;
+  ContentMainDelegateEfl();
+#if BUILDFLAG(IS_TIZEN_TV)
+  ~ContentMainDelegateEfl() override;
+#endif
 
   ContentMainDelegateEfl(const ContentMainDelegateEfl&) = delete;
   ContentMainDelegateEfl& operator=(const ContentMainDelegateEfl&) = delete;
@@ -31,12 +33,21 @@ class ContentMainDelegateEfl
 
   ContentBrowserClient* GetContentBrowserClient() const;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  void ProcessExiting(const std::string& process_type) override;
+  void SetInspectorStatus(bool enable);
+  bool GetInspectorStatus();
+#endif
+
  private:
   void PreSandboxStartupBrowser();
 
   std::unique_ptr<ContentBrowserClient> browser_client_;
   std::unique_ptr<ContentRendererClient> renderer_client_;
   ContentClientEfl content_client_;
+#if BUILDFLAG(IS_TIZEN_TV)
+  bool enableInspector_;
+#endif
 };
 
 }
index 3b76a9d..dc20abd 100644 (file)
@@ -19,6 +19,7 @@
 #include "common/version_info.h"
 #include "content/browser/devtools/devtools_http_handler.h"
 #include "content/browser/devtools/grit/devtools_resources.h"
+#include "content/browser/inspector/devtools_util_manager.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/devtools_agent_host.h"
 #include "content/public/browser/devtools_frontend_host.h"
 #include "content/shell/grit/shell_resources.h"
 #include "net/base/net_errors.h"
 #include "net/socket/tcp_server_socket.h"
+#include "third_party/zlib/google/compression_utils.h"
 #include "ui/base/resource/resource_bundle.h"
 
 using content::BrowserThread;
 using content::DevToolsHttpHandler;
 
-namespace {
-
-// Copy of internal class implementation from
-// content/shell/browser/shell_devtools_delegate.cc
-
-const uint16_t kMinTetheringPort = 9333;
-const uint16_t kMaxTetheringPort = 9444;
-const int kBackLog = 10;
-
-class TCPServerSocketFactory : public content::DevToolsSocketFactory {
- public:
-  TCPServerSocketFactory(const std::string& address, uint16_t port)
-      : address_(address), port_(port) {}
-
- private:
-  std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
-    std::unique_ptr<net::ServerSocket> socket(
-        new net::TCPServerSocket(nullptr, net::NetLogSource()));
-    if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK)
-      return std::unique_ptr<net::ServerSocket>();
-
-    return socket;
-  }
-
-  std::string address_;
-  uint16_t port_;
-};
-
-}  // namespace
-
 namespace content {
 
-DevToolsDelegateEfl::DevToolsDelegateEfl(int port) : port_(0) {
-  // It's a hacky way to early detected if port is available. The problem is
-  // that the only thing we can do after checking is hope that noone will take
-  // the port until it's initialized on IO thread again. The best approach would
-  // be creating async callbacks that would inform when inspector server started
-  // and on which port.
-  static std::string addr = "0.0.0.0";
-  std::unique_ptr<net::ServerSocket> sock(
-      new net::TCPServerSocket(NULL, net::NetLogSource()));
-
-  const base::CommandLine* const command_line =
-      base::CommandLine::ForCurrentProcess();
-  // See if the user specified a port on the command line (useful for
-  // automation). If not, use an ephemeral port by specifying 0.
-  if (!port && command_line->HasSwitch(switches::kRemoteDebuggingPort)) {
-    int temp_port = 0;
-    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;
-    }
-  }
-
-  // why backlog is 1?
-  if (sock->ListenWithAddressAndPort(addr, port, 1) != net::OK) {
-    port_ = 0;
-    return;
+/* LCOV_EXCL_START */
+std::string DevToolsDelegateEfl::GetDiscoveryPageHTML() {
+  std::string data =
+      std::string(ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
+          IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE));
+  if (data.length() > 2 && data[0] == '\x1F' && data[1] == '\x8B') {
+    std::string uncompressed_data;
+    if (compression::GzipUncompress(data, &uncompressed_data))
+      return uncompressed_data;
+    LOG(ERROR) << "Failed to uncompress ";
   }
-
-  net::IPEndPoint givenIp;
-  sock->GetLocalAddress(&givenIp);
-  port_ = givenIp.port();
-
-#if !defined(EWK_BRINGUP)  // FIXME: m67 bringup
-  // FIXME: EWK_BRINGUP definition should be removed.
-  std::unique_ptr<content::DevToolsSocketFactory> factory(
-      new TCPServerSocketFactory(addr, port_));
-
-  devtools_http_handler_.reset(new content::DevToolsHttpHandler(
-      std::move(factory), std::string(), this, base::FilePath(),
-      base::FilePath(),
-      EflWebView::VersionInfo::GetInstance()
-          ->ProductNameAndVersionForUserAgent(),
-      EflWebView::VersionInfo::GetInstance()->DefaultUserAgent()));
-#endif  // !defined(EWK_BRINGUP)
+  return data;
 }
 
-DevToolsDelegateEfl::~DevToolsDelegateEfl() {}
-
-void DevToolsDelegateEfl::Stop() {
-  if (devtools_http_handler_) {
-    // The call below destroys this.
-    devtools_http_handler_.reset();
-  } else {
-    BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
-  }
+std::string DevToolsDelegateEfl::GetFrontendResource(const std::string& path) {
+  return content::DevToolsUtilManager::GetInstance()->GetFrontendResource(path);
 }
 
-std::string DevToolsDelegateEfl::GetDiscoveryPageHTML() {
-  return ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
-      IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE);
+bool DevToolsDelegateEfl::HasBundledFrontendResources() {
+  return true;
 }
 
-std::string DevToolsDelegateEfl::GetFrontendResource(const std::string& path) {
-  return content::DevToolsFrontendHost::GetFrontendResource(path);
+#if defined(OS_TIZEN_TV_PRODUCT)
+void DevToolsDelegateEfl::ReleasePort() {
+  content::DevToolsUtilManager::GetInstance()->ReleasePort();
 }
+#endif
+/* LCOV_EXCL_STOP */
 
 }  // namespace content
index 5300512..8d47461 100644 (file)
@@ -18,27 +18,18 @@ class DevToolsHttpHandler;
 // This class is similar to ShellDevToolsDelegate, which also implements DevToolsHttpHandlerDelegate interface.
 class DevToolsDelegateEfl : public DevToolsManagerDelegate {
  public:
-  explicit DevToolsDelegateEfl(int = 0);
-  ~DevToolsDelegateEfl() override;
+  explicit DevToolsDelegateEfl() {}  // LCOV_EXCL_LINE
+  virtual ~DevToolsDelegateEfl() {}  // LCOV_EXCL_LIN
 
   // DevToolsManagerDelegate implementation.
   std::string GetDiscoveryPageHTML() override;
 
-  // Stops http server.
-  void Stop();
-
   std::string GetFrontendResource(const std::string& path);
 
-  DevToolsHttpHandler* devtools_http_handler() {
-    return devtools_http_handler_.get();
-  }
-  int port() const {
-    return port_;
-  }
-
- private:
-  int port_;
-  std::unique_ptr<DevToolsHttpHandler> devtools_http_handler_;
+  virtual bool HasBundledFrontendResources();
+#if BUILDFLAG(IS_TIZEN_TV)
+  void ReleasePort();
+#endif
 };
 
 } // namespace content
diff --git a/tizen_src/ewk/efl_integration/devtools_port_manager.cc b/tizen_src/ewk/efl_integration/devtools_port_manager.cc
new file mode 100644 (file)
index 0000000..4f35dba
--- /dev/null
@@ -0,0 +1,304 @@
+// Copyright 2016 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "devtools_port_manager.h"
+
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include "base/logging.h"
+#include "devtools_port_msg.h"
+#if defined(OS_TIZEN)
+#include <vconf/vconf.h>
+#endif
+namespace devtools_http_handler {
+
+DevToolsPortManager* DevToolsPortManager::s_PortManager = 0;
+const int DevToolsPortManager::s_ValidPortList[] = {
+    DevToolsPort_7011, DevToolsPort_7012, DevToolsPort_7013};
+const int DevToolsPortManager::s_ValidPortCount =
+    sizeof(s_ValidPortList) / sizeof(int);
+const int DevToolsPortManager::s_ProceeNameLength = 128;
+// The size of SHM is composed of
+// PortCount|Port1|Port2|Port3|pid1|pid2|pid3|appName1|appName2|appName3
+const int DevToolsPortManager::s_DevToolsPortSharedMemorySize =
+    sizeof(int) + DevToolsPortManager::s_ValidPortCount * sizeof(int) * 2 +
+    s_ProceeNameLength * sizeof(char) * 3;
+
+DevToolsPortManager* DevToolsPortManager::GetInstance() {
+  if (!s_PortManager) {
+    DevToolsPortSharedMemory* dpsm =
+        DevToolsPortSharedMemory::Create(s_DevToolsPortSharedMemorySize);
+    if (dpsm) {
+      char* memp = (char*)dpsm->Data();
+      s_PortManager = new DevToolsPortManager(dpsm);
+      s_PortManager->m_UsedPortList = (int*)(dpsm->Data());
+      s_PortManager->m_PIDList =
+          s_PortManager->m_UsedPortList + s_ValidPortCount + 1;
+      s_PortManager->m_AppName = memp;
+      s_PortManager->m_AppName +=
+          sizeof(int) + DevToolsPortManager::s_ValidPortCount * sizeof(int) * 2;
+    }
+  }
+
+  return s_PortManager;
+}
+
+DevToolsPortManager::DevToolsPortManager(DevToolsPortSharedMemory* p)
+    : m_UsedPortList(0), m_DevToolsSHM(p), usedPort(0) {}
+
+bool DevToolsPortManager::IsPortUsed(const int port) {
+  DevToolsLockHolder h(m_DevToolsSHM);
+
+  int usedPortCount = m_UsedPortList[0];
+  if (!usedPortCount)
+    return false;
+
+  if (usedPortCount <= s_ValidPortCount) {
+    while (usedPortCount > 0) {
+      if (m_UsedPortList[usedPortCount] == port &&
+          getpid() == m_PIDList[usedPortCount - 1])
+        return true;
+
+      usedPortCount--;
+    }
+  }
+
+  return false;
+}
+
+bool DevToolsPortManager::GetValidPort(int& port) {
+  int pid = 0;
+
+  if (GetValidPort(port, pid)) {
+    if (pid) {
+      DevToolsPortMsg* dpm = new DevToolsPortMsg();
+      dpm->Send(pid, port);
+    }
+    m_DevToolsSHM->Lock_Port(port);
+    if (pid)
+      UpdatePortInfoInMem(port);
+    return true;
+  }
+
+  return false;
+}
+
+bool DevToolsPortManager::GetValidPort(int& port, int& pid) {
+  DevToolsLockHolder h(m_DevToolsSHM);
+
+  int usedPortCount = m_UsedPortList[0];
+  if (usedPortCount == s_ValidPortCount) {
+    port = m_UsedPortList[1];
+    pid = m_PIDList[0];
+  } else {
+    int i = 0;
+    int j = 0;
+    bool selected = 0;
+    std::string processName = GetCurrentProcessName();
+    for (i = 0; i < s_ValidPortCount; i++) {
+      selected = 0;
+      for (j = 1; j <= usedPortCount; j++) {
+        if (s_ValidPortList[i] == m_UsedPortList[j])
+          selected = 1;
+      }
+      if (!selected)
+        break;
+    }
+    if (i < s_ValidPortCount && !selected) {
+      usedPortCount++;
+      m_UsedPortList[usedPortCount] = s_ValidPortList[i];
+      m_PIDList[usedPortCount - 1] = getpid();
+      memset(m_AppName + (usedPortCount - 1) * s_ProceeNameLength, 0,
+             s_ProceeNameLength);
+      memcpy(m_AppName + (usedPortCount - 1) * s_ProceeNameLength,
+             processName.c_str(), processName.length());
+      m_UsedPortList[0] = usedPortCount;
+      port = s_ValidPortList[i];
+    } else
+      return false;
+  }
+  return true;
+}
+
+void DevToolsPortManager::UpdatePortInfoInMem(int port) {
+  DevToolsLockHolder h(m_DevToolsSHM);
+  std::string processName = GetCurrentProcessName();
+  int usedPortCount = m_UsedPortList[0];
+
+  if (usedPortCount < s_ValidPortCount) {
+    usedPortCount++;
+    m_UsedPortList[usedPortCount] = port;
+    m_PIDList[usedPortCount - 1] = getpid();
+    memset(m_AppName + (usedPortCount - 1) * s_ProceeNameLength, 0,
+           s_ProceeNameLength);
+    memcpy(m_AppName + (usedPortCount - 1) * s_ProceeNameLength,
+           processName.c_str(), processName.length());
+    m_UsedPortList[0] = usedPortCount;
+  }
+}
+
+bool DevToolsPortManager::ReleasePort() {
+  DevToolsLockHolder h(m_DevToolsSHM);
+  std::string PrcocessName;
+  PrcocessName = DevToolsPortManager::GetCurrentProcessName();
+  int i;
+  int port = 0;
+  int usedPortCount = m_UsedPortList[0];
+  bool isPortExist = false;
+  if (usedPort)
+    port = usedPort;
+
+  if (!usedPortCount)
+    return false;
+  for (i = 1; i <= usedPortCount; i++) {
+    if (m_UsedPortList[i] == port && getpid() == m_PIDList[i - 1]) {
+      isPortExist = true;
+      break;
+    }
+  }
+  if (isPortExist) {
+    m_UsedPortList[i] = 0;
+    m_PIDList[i - 1] = 0;
+    memset(m_AppName + (i - 1) * s_ProceeNameLength, 0, s_ProceeNameLength);
+    for (int k = i + 1; k <= usedPortCount; k++) {
+      m_UsedPortList[i] = m_UsedPortList[k];
+      m_PIDList[i - 1] = m_PIDList[k - 1];
+      memset(m_AppName + (i - 1) * s_ProceeNameLength, 0, s_ProceeNameLength);
+      memcpy(m_AppName + (i - 1) * s_ProceeNameLength,
+             m_AppName + (k - 1) * s_ProceeNameLength, s_ProceeNameLength);
+      i++;
+    }
+    m_UsedPortList[usedPortCount] = 0;
+    m_PIDList[usedPortCount - 1] = 0;
+    memset(m_AppName + (usedPortCount - 1) * s_ProceeNameLength, 0,
+           s_ProceeNameLength);
+    usedPortCount--;
+    m_UsedPortList[0] = usedPortCount;
+    m_DevToolsSHM->UnLock_Port(usedPort);
+  }
+  return isPortExist;
+}
+
+bool DevToolsPortManager::IsValidPort(const int port) {
+  for (int i = 0; i < s_ValidPortCount; i++) {
+    if (s_ValidPortList[i] == port)
+      return true;
+  }
+
+  return false;
+}
+
+void DevToolsPortManager::GetMappingInfo(std::string& usedMappingInfo) {
+  DevToolsLockHolder h(m_DevToolsSHM);
+
+  int usedPortCount = m_UsedPortList[0];
+  std::string processName;
+  char portNumber[] = "  99999";
+  bool isPortExist = false;
+
+  if (usedPortCount <= 0 || usedPortCount > s_ValidPortCount)
+    return;
+
+  usedMappingInfo.append("RWI mapping info \n");
+
+  for (int i = 0; i < s_ValidPortCount; i++) {
+    isPortExist = false;
+
+    char processName[s_ProceeNameLength];
+
+    for (int j = 1; j <= usedPortCount; j++) {
+      if (s_ValidPortList[i] == m_UsedPortList[j]) {
+        isPortExist = true;
+        for (int k = 0; k < s_ProceeNameLength; k++)
+          processName[k] = m_AppName[k + (j - 1) * s_ProceeNameLength];
+
+        break;
+      }
+    }
+
+    snprintf(portNumber, sizeof(portNumber), "  %d", s_ValidPortList[i]);
+    usedMappingInfo.append(portNumber);
+    usedMappingInfo.append("(RWI):");
+    if (isPortExist)
+      usedMappingInfo.append(processName);
+    else
+      usedMappingInfo.append("N/A");
+
+    usedMappingInfo.append("\n");
+  }
+}
+
+bool DevToolsPortManager::ProcessCompare() {
+  std::string processName = GetCurrentProcessName();
+
+#if defined(OS_TIZEN)
+  char* vconfWidgetName = vconf_get_str("db/rwi/inspected_appid");
+#else
+  char* vconfWidgetName = NULL;
+#endif
+  if (!vconfWidgetName) {
+    LOG(INFO) << "[RWI]  vconf_ None";
+    return false;
+  }
+
+  std::string widgetName = vconfWidgetName;
+  free(vconfWidgetName);
+  LOG(INFO) << "[RWI] WidgetName = " << widgetName.c_str();
+  LOG(INFO) << "[RWI] ProcessName = " << processName.c_str();
+
+  if (!processName.empty()) {
+    if (widgetName == "org.tizen.browser")
+      widgetName = "browser";
+    else if(widgetName == "org.tizen.wizard")
+      widgetName = "wizard";
+
+    if (processName == widgetName)
+      return true;
+  }
+
+  return false;
+}
+
+std::string DevToolsPortManager::GetCurrentProcessName() {
+  std::string processName = GetUniqueName("/proc/self/cmdline");
+
+  if (!processName.empty()) {
+    unsigned int slashIndex = processName.rfind('/');
+
+    if (slashIndex != std::string::npos && slashIndex < processName.size())
+      processName = processName.substr(slashIndex + 1);
+  }
+
+  return processName;
+}
+
+std::string DevToolsPortManager::GetUniqueName(const char* name) {
+  if (!access(name, F_OK)) {
+    FILE* file = fopen(name, "r");
+
+    if (file) {
+      const int MAX_BUFF = 100;
+      char buff[MAX_BUFF] = {
+          0,
+      };
+      unsigned index = 0;
+
+      while (index < MAX_BUFF) {
+        int ch = fgetc(file);
+        if (ch == EOF)
+          break;
+
+        buff[index] = ch;
+        index++;
+      }
+
+      fclose(file);
+      return std::string(buff);
+    }
+  }
+  return std::string();
+}
+}  // namespace devtools_http_handler
diff --git a/tizen_src/ewk/efl_integration/devtools_port_manager.h b/tizen_src/ewk/efl_integration/devtools_port_manager.h
new file mode 100644 (file)
index 0000000..8fcf2c2
--- /dev/null
@@ -0,0 +1,62 @@
+// Copyright 2016 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVTOOLS_PORT_MANAGER_H_
+#define DEVTOOLS_PORT_MANAGER_H_
+
+#include "devtools_port_shared_memory.h"
+
+#include <string>
+#include <vector>
+
+namespace devtools_http_handler {
+enum DevToolsPortType {
+  DevToolsPort_7011 = 7011,
+  DevToolsPort_7012 = 7012,
+  DevToolsPort_7013 = 7013
+};
+
+class DevToolsPortManager {
+ public:
+  bool IsPortUsed(const int port);
+  bool GetValidPort(int& port);
+  bool GetValidPort(int& port, int& pid);
+  void GetMappingInfo(std::string& usedMappingInfo);
+  bool ReleasePort();
+  void SetPort(const int port) { usedPort = port; }
+  int GetPort() { return usedPort; }
+  void UpdatePortInfoInMem(int port);
+  void DumpSharedMemeory();
+
+  ~DevToolsPortManager();
+
+  static DevToolsPortManager* GetInstance();
+  static bool ProcessCompare();
+  static std::string GetCurrentProcessName();
+  static std::string GetUniqueName(const char* name);
+
+ private:
+  DevToolsPortManager(DevToolsPortSharedMemory*);
+  bool IsValidPort(const int port);
+
+  // PortCount|Port1|Port2|Port3
+  int* m_UsedPortList;
+  // pid1|pid2|pid3
+  int* m_PIDList;
+  // appName1|appName2|appName3
+  char* m_AppName;
+
+  DevToolsPortSharedMemory* m_DevToolsSHM;
+
+  int usedPort;
+
+  static DevToolsPortManager* s_PortManager;
+
+  static const int s_ValidPortList[];
+  static const int s_ValidPortCount;
+  static const int s_DevToolsPortSharedMemorySize;
+  static const int s_ProceeNameLength;
+};
+}  // namespace devtools_http_handler
+#endif  // DEVTOOLS_PORT_MANAGER_H_
diff --git a/tizen_src/ewk/efl_integration/devtools_port_msg.cc b/tizen_src/ewk/efl_integration/devtools_port_msg.cc
new file mode 100644 (file)
index 0000000..ea89831
--- /dev/null
@@ -0,0 +1,67 @@
+// Copyright 2016 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "devtools_port_msg.h"
+
+#include <arpa/inet.h>
+#include <net/if.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+bool DevToolsPortMsg::Send(int pid, int port) {
+  int sockfd;
+  struct ifreq ifr;
+  sockfd = socket(AF_INET, SOCK_STREAM, 0);
+  char eth[] = "eth0";
+  ifr.ifr_addr.sa_family = AF_INET;
+  strncpy(ifr.ifr_name, eth, sizeof(eth));
+
+  if (ioctl(sockfd, SIOCGIFADDR, &ifr) < 0) {
+    close(sockfd);
+    return false;
+  }
+  struct sockaddr_in servaddr;
+  bzero(&servaddr, sizeof(servaddr));
+  servaddr.sin_family = AF_INET;
+  servaddr.sin_port = htons(port);
+
+  char* addr = inet_ntoa(((struct sockaddr_in*)&(ifr.ifr_addr))->sin_addr);
+  if (inet_pton(AF_INET, addr, &servaddr.sin_addr) <= 0) {
+    close(sockfd);
+    return false;
+  }
+
+  if (connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0) {
+    return false;
+  }
+  const int str_len = 128;
+  char closeport[str_len];
+  memset(closeport, 0, str_len);
+  strncat(closeport, "GET /closeport HTTP/1.1\n",
+          sizeof(closeport) - strlen(closeport) - 1);
+  strncat(closeport, "\r\n", sizeof(closeport) - strlen(closeport) - 1);
+  int send_size =
+      send(sockfd, closeport, strlen(closeport), MSG_WAITALL | MSG_NOSIGNAL);
+
+  if (send_size < 0) {
+    close(sockfd);
+    return false;
+  } else {
+    while (1) {
+      char read_buf[str_len];
+      memset(read_buf, 0, str_len);
+      int read_size = read(sockfd, read_buf, str_len);
+      if (read_size) {
+        continue;
+      } else {
+        close(sockfd);
+        return true;
+      }
+    }
+  }
+  close(sockfd);
+  return false;
+}
diff --git a/tizen_src/ewk/efl_integration/devtools_port_msg.h b/tizen_src/ewk/efl_integration/devtools_port_msg.h
new file mode 100644 (file)
index 0000000..d9b1fdd
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2016 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVTOOLS_PORT_MSG_H_
+#define DEVTOOLS_PORT_MSG_H_
+
+class DevToolsPortMsg {
+ public:
+  DevToolsPortMsg(){};
+  bool Send(int pid, int port);
+};
+
+#endif  // DEVTOOLS_PORT_MSG_H_
diff --git a/tizen_src/ewk/efl_integration/devtools_port_shared_memory.cc b/tizen_src/ewk/efl_integration/devtools_port_shared_memory.cc
new file mode 100644 (file)
index 0000000..c4ce11e
--- /dev/null
@@ -0,0 +1,137 @@
+// Copyright 2016 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "devtools_port_shared_memory.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+namespace devtools_http_handler {
+const char* SEM_NAME_ARRAY[4] = {"DevToolsPort.lock", "DevToolsPort.lock_7011",
+                                 "DevToolsPort.lock_7012",
+                                 "DevToolsPort.lock_7013"};
+#define INSPECTOR_PORT_7011 7011
+#define INSPECTOR_PORT_7012 7012
+#define INSPECTOR_PORT_7013 7013
+
+DevToolsLocker::DevToolsLocker(int port) : m_sem(0) {
+  const char* sem_name;
+  if (!port)
+    sem_name = SEM_NAME_ARRAY[0];
+  else
+    sem_name = SEM_NAME_ARRAY[port - 7010];
+  m_port = port;
+  m_sem = sem_open(sem_name, O_CREAT, 0644, 1);
+  if (m_sem == SEM_FAILED)
+    sem_unlink(sem_name);
+}
+
+DevToolsLocker::~DevToolsLocker() {
+  const char* sem_name;
+  if (!m_sem)
+    return;
+  if (!m_port)
+    sem_name = SEM_NAME_ARRAY[m_port];
+  else
+    sem_name = SEM_NAME_ARRAY[m_port - 7010];
+  sem_close(m_sem);
+}
+
+bool DevToolsLocker::Lock() {
+  if (!m_sem)
+    return false;
+
+  int result = sem_wait(m_sem);
+
+  return !result;
+}
+
+bool DevToolsLocker::TryLock() {
+  if (!m_sem)
+    return false;
+
+  int result = sem_trywait(m_sem);
+
+  return !result;
+}
+
+bool DevToolsLocker::Unlock() {
+  if (!m_sem)
+    return false;
+
+  int result = sem_post(m_sem);
+
+  return !result;
+}
+
+const char* DevToolsPortSharedMemory::s_SHMKey =
+    "/WK2SharedMemory.inspector.port";
+
+DevToolsPortSharedMemory::DevToolsPortSharedMemory() {
+  for (int i = 0; i < 3; i++) {
+    m_PortLocker[i] = new DevToolsLocker(i + 7011);
+  }
+}
+
+DevToolsPortSharedMemory::~DevToolsPortSharedMemory() {
+  if (!(*(int*)m_data))
+    shm_unlink(s_SHMKey);
+
+  for (int i = 0; i < 3; i++) {
+    if (m_PortLocker[i])
+      delete (m_PortLocker[i]);
+  }
+  munmap(m_data, m_size);
+}
+
+void DevToolsPortSharedMemory::Lock_Port(int port) {
+  if (port >= INSPECTOR_PORT_7011 && port <= INSPECTOR_PORT_7013)
+    m_PortLocker[port - INSPECTOR_PORT_7011]->Lock();
+}
+
+void DevToolsPortSharedMemory::UnLock_Port(int port) {
+  if (port >= INSPECTOR_PORT_7011 && port <= INSPECTOR_PORT_7013)
+    m_PortLocker[port - INSPECTOR_PORT_7011]->Unlock();
+}
+
+bool DevToolsPortSharedMemory::Lock() {
+  return m_Locker.Lock();
+}
+
+bool DevToolsPortSharedMemory::Unlock() {
+  return m_Locker.Unlock();
+}
+
+DevToolsPortSharedMemory* DevToolsPortSharedMemory::Create(size_t size) {
+  int fd = shm_open(s_SHMKey, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
+  if (fd == -1)
+    return 0;
+
+  while (ftruncate(fd, size) == -1) {
+    if (errno != EINTR) {
+      close(fd);
+      shm_unlink(s_SHMKey);
+      return 0;
+    }
+  }
+
+  void* data = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+  if (data == MAP_FAILED) {
+    close(fd);
+    shm_unlink(s_SHMKey);
+    return 0;
+  }
+
+  close(fd);
+
+  static DevToolsPortSharedMemory devtoolsSHM;
+  devtoolsSHM.m_data = data;
+  devtoolsSHM.m_size = size;
+
+  return &devtoolsSHM;
+}
+}  // namespace devtools_http_handler
diff --git a/tizen_src/ewk/efl_integration/devtools_port_shared_memory.h b/tizen_src/ewk/efl_integration/devtools_port_shared_memory.h
new file mode 100644 (file)
index 0000000..a44091c
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright 2016 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVTOOLS_PORT_SHARED_MEMORY_H_
+#define DEVTOOLS_PORT_SHARED_MEMORY_H_
+
+#include <semaphore.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <sys/file.h>
+
+namespace devtools_http_handler {
+
+class DevToolsLocker {
+ public:
+  DevToolsLocker(int port = 0);
+  ~DevToolsLocker();
+  bool Lock();
+  bool TryLock();
+  bool Unlock();
+
+ private:
+  sem_t* m_sem;
+  int m_port;
+};
+
+class DevToolsPortSharedMemory {
+ public:
+  // Create a shared memory object with the given size. Will return 0 on
+  // failure.
+  static DevToolsPortSharedMemory* Create(size_t);
+
+  ~DevToolsPortSharedMemory();
+
+  size_t Size() const { return m_size; }
+  void* Data() const { return m_data; }
+  bool Lock();
+  bool Unlock();
+  void Lock_Port(int port);
+  void UnLock_Port(int port);
+
+ private:
+  static const char* s_SHMKey;
+  size_t m_size;
+  void* m_data;
+  DevToolsLocker m_Locker;
+  DevToolsLocker* m_PortLocker[3];
+  DevToolsPortSharedMemory();
+};
+
+class DevToolsLockHolder {
+ private:
+  DevToolsPortSharedMemory* m_lock;
+
+ public:
+  inline explicit DevToolsLockHolder(DevToolsPortSharedMemory* shmLock)
+      : m_lock(shmLock) {
+    shmLock->Lock();
+  }
+  inline ~DevToolsLockHolder() { m_lock->Unlock(); }
+};
+}  // namespace devtools_http_handler
+#endif  // DEVTOOLS_PORT_SHARED_MEMORY_H_
index ff0aaef..0d9f7a7 100644 (file)
@@ -20,6 +20,7 @@
 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
 #include "components/password_manager/core/browser/password_form.h"
 #include "components/password_manager/core/browser/password_store.h"
+#include "content/browser/inspector/devtools_util_manager.h"
 #include "components/services/storage/public/cpp/buckets/bucket_locator.h"
 #include "content/public/browser/browser_context.h"
 #include "content/public/browser/browser_task_traits.h"
@@ -66,6 +67,8 @@
 
 #if BUILDFLAG(IS_TIZEN_TV)
 #include "common/application_type.h"
+#include "content_main_delegate_efl.h"
+#include "net/disk_cache/cache_util.h"
 #include "wrt/hbbtv_dynamicplugin.h"
 #include "wrt/hbbtv_widget_host.h"
 #endif
@@ -331,6 +334,7 @@ EWebContext::EWebContext(bool incognito, const std::string& injectedBundlePath)
       widget_scale_(0),
 #if BUILDFLAG(IS_TIZEN_TV)
       application_type_(EWK_APPLICATION_TYPE_WEBBROWSER),
+      is_showing_mapping_info_(false),
 #endif
       m_pixmap(0),
       inspector_server_(NULL) {
@@ -872,18 +876,28 @@ void EWebContext::GetPasswordDataList(
 }
 
 unsigned int EWebContext::InspectorServerStart(unsigned int port) {
+    LOG(INFO) << "EWebContext::InspectorServerStart";
+#if BUILDFLAG(IS_TIZEN_TV)
+  is_showing_mapping_info_ = true;
+  EwkGlobalData::GetInstance()->GetContentMainDelegateEfl().SetInspectorStatus(
+      true);
+  if (content::DevToolsUtilManager::GetPort())
+    return content::DevToolsUtilManager::GetPort();
+#endif
   InspectorServerStop();
-  inspector_server_ = new content::DevToolsDelegateEfl(port);
-  return inspector_server_ ? inspector_server_->port() : 0;
+  return content::DevToolsUtilManager::GetInstance()->InspectorServerStart(
+      port);
 }
 
 bool EWebContext::InspectorServerStop() {
-  if (!inspector_server_)
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (!content::DevToolsUtilManager::GetPort())
     return false;
-  // The call below destroys inspector_server_.
-  inspector_server_->Stop();
-  inspector_server_ = NULL;
-  return true;
+  is_showing_mapping_info_ = false;
+  EwkGlobalData::GetInstance()->GetContentMainDelegateEfl().SetInspectorStatus(
+      false);
+#endif
+  return content::DevToolsUtilManager::GetInstance()->InspectorServerStop();
 }
 
 void EWebContext::SetNotificationCallbacks(
@@ -989,6 +1003,18 @@ void EWebContext::SetApplicationType(
   }
 }
 
+bool EWebContext::GetInspectorServerState() {
+  return content::DevToolsUtilManager::GetPort();
+}
+
+bool EWebContext::ShowInspectorPortInfoState() {
+  if (!is_showing_mapping_info_)
+    return false;
+
+  is_showing_mapping_info_ = false;
+  return content::DevToolsUtilManager::GetPort();
+}
+
 void EWebContext::RegisterJSPluginMimeTypes(const Eina_List* mime_types_list) {
   std::string mime_types;
   const Eina_List* it;
index 067c619..dab08bc 100644 (file)
@@ -202,6 +202,9 @@ class EWebContext {
 #if BUILDFLAG(IS_TIZEN_TV)
   void SetApplicationType(const Ewk_Application_Type application_type);
   Ewk_Application_Type GetApplicationType() const { return application_type_; }
+  // To control applocation only show once inspector port info
+  bool ShowInspectorPortInfoState();
+  bool GetInspectorServerState();
   void RegisterJSPluginMimeTypes(const Eina_List*);
   void RegisterURLSchemesAsCORSEnabled(const Eina_List* schemes_list);
   void SetTimeOffset(double time_offset);
@@ -246,6 +249,8 @@ class EWebContext {
   int m_pixmap;
 #if BUILDFLAG(IS_TIZEN_TV)
   Ewk_Application_Type application_type_;
+  // For processes which are preloaded and with unknown app id
+  bool is_showing_mapping_info_;
 #endif
 
   content::DevToolsDelegateEfl* inspector_server_;
index 909d773..e459577 100644 (file)
 #include "components/autofill/core/common/autofill_switches.h"
 #endif
 
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "common/application_type.h"
+#include "devtools_port_manager.h"
+#include "public/ewk_media_downloadable_font_info.h"
+#endif // OS_TIZEN_TV_PRODUCT
+
 using namespace content;
 using web_contents_utils::WebViewFromWebContents;
 
@@ -333,6 +339,10 @@ EWebView::EWebView(Ewk_Context* context, Evas_Object* object)
       page_scale_factor_(1.0),
       x_delta_(0.0),
       y_delta_(0.0),
+#if BUILDFLAG(IS_TIZEN_TV)
+      use_early_rwi_(false),
+      rwi_info_showed_(false),
+#endif
       is_initialized_(false) {
  if (evas_object_) {
    evas_object_smart_callback_add(evas_object_,
@@ -618,6 +628,15 @@ void EWebView::SetURL(const GURL& url, bool from_api) {
         ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_FROM_API);
   }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (use_early_rwi_) {
+    LOG(INFO) << "[FAST RWI] SetURL Replace [" << url.spec()
+              << "] to [about:blank]";
+    rwi_gurl_ = url;
+    params.url = GURL("about:blank");
+  }
+#endif
+
   params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE;
   web_contents_->GetController().LoadURLWithParams(params);
 }
@@ -2486,10 +2505,30 @@ std::string EWebView::GetPlatformLocale() {
 }
 
 int EWebView::StartInspectorServer(int port) {
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (IsTIZENWRT()) {
+    use_early_rwi_ = false;
+    rwi_info_showed_ = false;
+  }
+  if (!context_->GetImpl()->GetInspectorServerState()) {
+    int validPort = 0;
+    if (!devtools_http_handler::DevToolsPortManager::GetInstance()
+             ->GetValidPort(validPort))
+      return 0;
+
+    port = validPort;
+  }
+#endif
   return context_->InspectorServerStart(port);
 }
 
 bool EWebView::StopInspectorServer() {
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (IsTIZENWRT()) {
+    use_early_rwi_ = false;
+    rwi_info_showed_ = false;
+  }
+#endif
   return context_->InspectorServerStop();
 }
 
@@ -2525,6 +2564,11 @@ void EWebView::HandleRendererProcessCrash() {
 }
 
 void EWebView::InitializeContent() {
+  LOG(INFO) << "eweb_view.cc  InitializeContent" ;
+#if BUILDFLAG(IS_TIZEN_TV)
+  // When initialize content init inspector server
+  InitInspectorServer();
+#endif
   WebContents* new_contents = create_new_window_web_contents_cb_.Run(this);
   if (!new_contents) {
     WebContents::CreateParams params(context_->browser_context());
@@ -2595,6 +2639,31 @@ void EWebView::InitializeContent() {
   InitializeWindowTreeHost();
 }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+void EWebView::OnDialogClosed() {
+  if (!use_early_rwi_)
+    return;
+
+  use_early_rwi_ = false;
+  LOG(INFO) << "[FAST RWI] SetURL Restore [" << rwi_gurl_.spec()
+            << "] from [about:blank]";
+  SetURL(rwi_gurl_);
+  rwi_gurl_ = GURL();
+  rwi_info_showed_ = true;
+}
+
+void EWebView::InitInspectorServer() {
+  if (devtools_http_handler::DevToolsPortManager::GetInstance()
+          ->ProcessCompare()) {
+    int res = StartInspectorServer(0);
+    if (res) {
+      LOG(INFO) << "InitInspectorServer SetPort";
+      devtools_http_handler::DevToolsPortManager::GetInstance()->SetPort(res);
+    }
+  }
+}
+#endif
+
 void EWebView::InitializeWindowTreeHost() {
   CHECK(aura::Env::GetInstance());
 
index bd71c11..6f05ceb 100644 (file)
@@ -712,6 +712,15 @@ class EWebView {
 
   void OnSelectionRectReceived(const gfx::Rect& selection_rect) const;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  bool SetMixedContents(bool allow);
+  void ClearAllTilesResources();
+  bool UseEarlyRWI() { return use_early_rwi_; }
+  bool RWIInfoShowed() { return rwi_info_showed_; }
+  GURL RWIURL() { return rwi_gurl_; }
+  void OnDialogClosed();
+#endif // OS_TIZEN_TV_PRODUCT
+
  private:
   static void NativeViewResize(void* data,
                                Evas* e,
@@ -727,6 +736,11 @@ class EWebView {
       int y,
       Ewk_Hit_Test_Mode mode,
       WebViewAsyncRequestHitTestDataCallback* cb);
+
+#if BUILDFLAG(IS_TIZEN_TV)
+  void InitInspectorServer();
+#endif
+
 #if BUILDFLAG(IS_TIZEN) && !defined(EWK_BRINGUP)
   static void cameraResultCb(service_h request,
                              service_h reply,
@@ -890,6 +904,12 @@ class EWebView {
 
   bool is_initialized_;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  bool use_early_rwi_;
+  bool rwi_info_showed_;
+  GURL rwi_gurl_;
+#endif
+
   std::unique_ptr<_Ewk_Back_Forward_List> back_forward_list_;
 
   static content::WebContentsEflDelegate::WebContentsCreateCallback
index 1b9ab28..4fd18d2 100644 (file)
 #include "browser/autofill/autofill_request_manager.h"
 #endif
 
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "devtools_port_manager.h"
+#endif // OS_TIZEN_TV_PRODUCT
+
 #if defined(TIZEN_AUTOFILL)
 #include "base/command_line.h"
 #include "browser/autofill/autofill_client_efl.h"
@@ -154,6 +158,10 @@ WebContentsDelegateEfl::~WebContentsDelegateEfl() {
     delete dialog_manager_;
 }
 
+static bool IsMainFrame(RenderFrameHost* render_frame_host) {
+  return !render_frame_host->GetParent();
+}
+
 WebContents* WebContentsDelegateEfl::OpenURLFromTab(
     WebContents* source,
     const OpenURLParams& params) {
@@ -684,6 +692,40 @@ void WebContentsDelegateEfl::OnDidGetManifest(
 }
 
 #if BUILDFLAG(IS_TIZEN_TV)
+void WebContentsDelegateEfl::ShowInspectorPortInfo() {
+  std::string mappingInfo;
+  devtools_http_handler::DevToolsPortManager::GetInstance()->GetMappingInfo(
+      mappingInfo);
+  if (web_view_->UseEarlyRWI()) {
+    mappingInfo.append(
+        "\r\nFast RWI is used, [about:blank] is loaded fist instead of \r\n[");
+    mappingInfo.append(web_view_->RWIURL().spec());
+    mappingInfo.append(
+        "]\r\nClick OK button will start the real loading.\r\nNotes:\r\nPlease "
+        "connect to RWI in PC before click OK button.\r\nThen you can get "
+        "network log from the initial loading.\r\nPlease click Record button "
+        "in Timeline panel in PC before click OK button,\r\nThen you can get "
+        "profile log from the initial loading.");
+  }
+  LOG(INFO) << "[RWI] WebContentsDelegateEfl::ShowPortInfo mappingInfo = "
+            << mappingInfo.c_str();
+
+  if (!mappingInfo.empty()) {
+    const GURL kGURL("");
+    WebContentsImpl* wci = static_cast<WebContentsImpl*>(&web_contents_);
+    auto dialog_closed_callback =
+        base::BindOnce([](JavaScriptDialogManager* manager, bool success,
+                          const std::u16string& response) {},
+                       dialog_manager_);
+    wci->RunJavaScriptDialog(
+        wci->GetPrimaryMainFrame(), base::ASCIIToUTF16(mappingInfo),
+        base::ASCIIToUTF16(base::StringPiece("OK")),
+        JAVASCRIPT_DIALOG_TYPE_ALERT, false, std::move(dialog_closed_callback));
+  }
+}
+#endif
+
+#if BUILDFLAG(IS_TIZEN_TV)
 void WebContentsDelegateEfl::UpdateTargetURL(WebContents* /*source*/,
                                              const GURL& url) {
   std::string absolute_link_url(url.spec());
index a396563..70b905a 100644 (file)
@@ -129,6 +129,7 @@ class WebContentsDelegateEfl : public WebContentsDelegate {
 
 #if BUILDFLAG(IS_TIZEN_TV)
   void UpdateTargetURL(WebContents* source, const GURL& url) override;
+  void ShowInspectorPortInfo();
 #endif
 
 #if defined(TIZEN_AUTOFILL)
index 415d1c8..8768401 100644 (file)
@@ -30,9 +30,6 @@
 #include "url/gurl.h"
 
 #if defined(OS_TIZEN_TV_PRODUCT)
-#if !defined(EWK_BRINGUP)
-#include "devtools_port_manager.h"
-#endif
 #include "private/ewk_context_private.h"
 #endif
 
@@ -142,10 +139,21 @@ void WebContentsObserverEfl::LoadProgressChanged(double progress) {
 
 void WebContentsObserverEfl::DidFinishLoad(RenderFrameHost* render_frame_host,
                                            const GURL& validated_url) {
+  LOG(INFO) << "WebContentsObserverEfl::DidFinishLoad";
   if (!IsMainFrame(render_frame_host))
     return;
   web_view_->SmartCallback<EWebViewCallbacks::LoadFinished>().call();
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  // After load finish show inspector port info
+  if (web_view_->context() && web_view_->context()->GetImpl() &&
+      web_view_->context()->GetImpl()->ShowInspectorPortInfoState()) {
+    if (!web_view_->RWIInfoShowed())
+      web_contents_delegate_->ShowInspectorPortInfo();
+  }
+#endif
+
+  TTRACE_WEB("WebContentsObserverEfl::DidFinishLoad");
   web_contents_.Focus();
 }
 
index 6951437..1b8273c 100644 (file)
@@ -17,9 +17,7 @@
 #include "electron/shell/common/gin_converters/content_converter.h"
 #include "gin/object_template_builder.h"
 #include "tizen_src/chromium_impl/tizen/vconf_handle.h"
-#if !defined(WRT_JS_BRINGUP)
 #include "tizen_src/ewk/efl_integration/devtools_port_manager.h"
-#endif
 #include "v8/include/v8.h"
 #include "wrt/src/base/platform_info.h"
 #include "wrt/src/browser/native_web_runtime.h"
@@ -140,12 +138,11 @@ TVExtension::TVExtension() {}
 TVExtension::~TVExtension() {}
 
 bool TVExtension::NeedUseInspector() const {
-#if defined(WRT_JS_BRINGUP)
+  if (devtools_http_handler::DevToolsPortManager::GetInstance()
+          ->ProcessCompare()) {
+    return true;
+  }
   return false;
-#else
-  return devtools_http_handler::DevToolsPortManager::GetInstance()
-      ->ProcessCompare();
-#endif
 }
 
 bool TVExtension::IsAlwaysReload() const {
index 619c3c4..c845c00 100755 (executable)
@@ -16,9 +16,7 @@
 #include "electron/shell/common/gin_helper/dictionary.h"
 #include "electron/shell/common/node_includes.h"
 #include "gin/object_template_builder.h"
-#if !defined(WRT_JS_BRINGUP)
 #include "tizen_src/chromium_impl/content/browser/inspector/devtools_util_manager.h"
-#endif
 #include "tizen_src/chromium_impl/efl/window_factory.h"
 #include "tizen_src/chromium_impl/tizen/system_info.h"
 #include "wrt/src/base/file_utils.h"
@@ -225,15 +223,11 @@ bool WebRuntime::GetBackgroundSupport() const {
 }
 
 unsigned int WebRuntime::StartInspectorServer() const {
-#if !defined(WRT_JS_BRINGUP)
   return content::DevToolsUtilManager::GetInstance()->InspectorServerStart();
-#endif
 }
 
 void WebRuntime::StopInspectorServer() const {
-#if !defined(WRT_JS_BRINGUP)
   content::DevToolsUtilManager::GetInstance()->InspectorServerStop();
-#endif
 }
 
 void WebRuntime::HandleCertificateError(
@@ -715,6 +709,7 @@ gin::ObjectTemplateBuilder WebRuntime::GetObjectTemplateBuilder(
     v8::Isolate* isolate) {
   auto object_builder =
       gin::Wrappable<WebRuntime>::GetObjectTemplateBuilder(isolate);
+
   if (!ApplicationData::IsServiceApp()) {
     object_builder
         .SetMethod("exit", &WebRuntime::Exit)
index 0994039..cdd7358 100755 (executable)
@@ -4,7 +4,7 @@
 
 #include "wrt/src/browser/wrt_devtools_manager_delegate.h"
 
-#if BUILDFLAG(IS_TIZEN_TV) && !defined(WRT_JS_BRINGUP)
+#if BUILDFLAG(IS_TIZEN_TV)
 #include "tizen_src/chromium_impl/content/browser/inspector/devtools_util_manager.h"
 #endif
 
@@ -14,7 +14,7 @@ bool WRTDevToolsManagerDelegate::HasBundledFrontendResources() {
   return true;
 }
 
-#if BUILDFLAG(IS_TIZEN_TV) && !defined(WRT_JS_BRINGUP)
+#if BUILDFLAG(IS_TIZEN_TV)
 void WRTDevToolsManagerDelegate::ReleasePort() {
   content::DevToolsUtilManager::GetInstance()->ReleasePort();
 }
index eeb95cc..31776a3 100755 (executable)
@@ -19,7 +19,7 @@ class WRTDevToolsManagerDelegate : public electron::DevToolsManagerDelegate {
       = delete;
 
   // Chromium DevToolsHttpHandler::Delegate overrides.
-#if BUILDFLAG(IS_TIZEN_TV) && !defined(WRT_JS_BRINGUP)
+#if BUILDFLAG(IS_TIZEN_TV)
   void ReleasePort() override;
 #endif