Add Tizen-platform implementation of EditorClient
authorSeungSeop Park <sns.park@samsung.com>
Thu, 29 May 2014 15:53:32 +0000 (11:53 -0400)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
Change-Id: Iff5a6024a118dd1a3e536538ca04d7a5f1b8ae6a

tizen_src/impl/chromium-efl.gyp
tizen_src/impl/components/editing/content/browser/editor_client_observer.cc [new file with mode: 0644]
tizen_src/impl/components/editing/content/browser/editor_client_observer.h [new file with mode: 0644]
tizen_src/impl/components/editing/content/common/editing_messages.h [new file with mode: 0644]
tizen_src/impl/components/editing/content/renderer/editorclient_agent.cc [new file with mode: 0644]
tizen_src/impl/components/editing/content/renderer/editorclient_agent.h [new file with mode: 0644]

index 28aea20f54ecd578edaa3b6fbbe63fc3346fa406..fd271164a5bac3d32bf73db5eb984a78a7871140 100644 (file)
       'components/clipboard/clipboard_efl.cc',
       'components/clipboard/clipboard_helper_efl.cc',
       'components/clipboard/clipboard_helper_efl.h',
+      'components/editing/content/browser/editor_client_observer.cc',
+      'components/editing/content/browser/editor_client_observer.h',
+      'components/editing/content/common/editing_messages.h',
+      'components/editing/content/renderer/editorclient_agent.cc',
+      'components/editing/content/renderer/editorclient_agent.h',
       'context_menu_controller_efl.cc',
       'context_menu_controller_efl.h',
       'cookie_manager.cc',
diff --git a/tizen_src/impl/components/editing/content/browser/editor_client_observer.cc b/tizen_src/impl/components/editing/content/browser/editor_client_observer.cc
new file mode 100644 (file)
index 0000000..dc7287c
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2013 Samsung Electronics. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ */
+
+#include "editor_client_observer.h"
+
+#include <stddef.h>
+#include <limits>
+#include <map>
+#include <set>
+#include <utility>
+
+#include "base/bind.h"
+#include "base/strings/string16.h"
+#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_view_host.h"
+
+#include "eweb_view.h"
+#include "web_contents_delegate_efl.h"
+#include "common/web_contents_utils.h"
+#include "components/editing/content/common/editing_messages.h"
+
+namespace editing {
+
+EWebView* GetWebViewFromId(int render_process_id, int render_view_id) {
+  content::WebContents* web_contents = web_contents_utils::WebContentsFromViewID(render_process_id,
+                                                                                        render_view_id);
+  if (!web_contents)
+    return NULL;
+
+  content::WebContentsDelegateEfl* delegate = static_cast<content::WebContentsDelegateEfl*>(web_contents->
+                                                                                            GetDelegate());
+  if (!delegate)
+    return NULL;
+  return (delegate->web_view());
+}
+
+EditorClientObserver::EditorClientObserver(int render_process_id)
+    : BrowserMessageFilter(ViewMsgStart)
+    , render_process_id_(render_process_id) {
+}
+
+void EditorClientObserver::OverrideThreadForMessage(const IPC::Message& message,
+                                                    content::BrowserThread::ID* thread) {
+  switch (message.type()) {
+    case EditingHostMsg_NotifyUndo::ID:
+    case EditingHostMsg_NotifyRedo::ID:
+    case EditingHostMsg_NotifyRegisterUndo::ID:
+    case EditingHostMsg_NotifyRegisterRedo::ID:
+    case EditingHostMsg_NotifyClearUndo::ID:
+    case EditingHostMsg_NotifyClearRedo::ID:
+      *thread = content::BrowserThread::UI;
+      break;
+    default:
+      break;
+  }
+}
+
+bool EditorClientObserver::OnMessageReceived(const IPC::Message& message) {
+  bool handled = true;
+  IPC_BEGIN_MESSAGE_MAP(EditorClientObserver, message)
+    IPC_MESSAGE_HANDLER(EditingHostMsg_NotifyUndo,
+                        OnUndoNotify)
+    IPC_MESSAGE_HANDLER(EditingHostMsg_NotifyRedo,
+                        OnRedoNotify)
+    IPC_MESSAGE_HANDLER(EditingHostMsg_NotifyRegisterUndo,
+                        OnRegisterUndoNotify)
+    IPC_MESSAGE_HANDLER(EditingHostMsg_NotifyRegisterRedo,
+                        OnRegisterRedoNotify)
+    IPC_MESSAGE_HANDLER(EditingHostMsg_NotifyClearUndo,
+                        OnClearUndoStackNotify)
+    IPC_MESSAGE_HANDLER(EditingHostMsg_NotifyClearRedo,
+                        OnClearRedoStackNotify)
+    IPC_MESSAGE_UNHANDLED(handled = false)
+  IPC_END_MESSAGE_MAP()
+  return handled;
+}
+
+void EditorClientObserver::OnUndoNotify(int render_view_id, size_t undoStackSize) {
+  EWebView* web_view = GetWebViewFromId(render_process_id_, render_view_id);
+  if (web_view)
+    web_view->SmartCallback<EWebViewCallbacks::UndoSize>().call(&undoStackSize);
+}
+
+void EditorClientObserver::OnRedoNotify(int render_view_id, size_t redoStackSize) {
+  EWebView* web_view = GetWebViewFromId(render_process_id_, render_view_id);
+  if (web_view)
+    web_view->SmartCallback<EWebViewCallbacks::RedoSize>().call(&redoStackSize);
+}
+
+void EditorClientObserver::OnRegisterUndoNotify(int render_view_id, size_t undoStackSize) {
+  EWebView* web_view = GetWebViewFromId(render_process_id_, render_view_id);
+  if (web_view)
+    web_view->SmartCallback<EWebViewCallbacks::UndoSize>().call(&undoStackSize);
+}
+
+void EditorClientObserver::OnRegisterRedoNotify(int render_view_id, size_t redoStackSize) {
+  EWebView* web_view = GetWebViewFromId(render_process_id_, render_view_id);
+  if (web_view)
+    web_view->SmartCallback<EWebViewCallbacks::RedoSize>().call(&redoStackSize);
+}
+
+void EditorClientObserver::OnClearUndoStackNotify(int render_view_id, size_t undoStackSize) {
+  EWebView* web_view = GetWebViewFromId(render_process_id_, render_view_id);
+  if (web_view)
+    web_view->SmartCallback<EWebViewCallbacks::UndoSize>().call(&undoStackSize);
+}
+
+void EditorClientObserver::OnClearRedoStackNotify(int render_view_id, size_t redoStackSize) {
+  EWebView* web_view = GetWebViewFromId(render_process_id_, render_view_id);
+  if (web_view)
+    web_view->SmartCallback<EWebViewCallbacks::RedoSize>().call(&redoStackSize);
+}
+
+}  // namespace editing
diff --git a/tizen_src/impl/components/editing/content/browser/editor_client_observer.h b/tizen_src/impl/components/editing/content/browser/editor_client_observer.h
new file mode 100644 (file)
index 0000000..5226396
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2013 Samsung Electronics. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ */
+
+#ifndef COMPONENTS_EDITING_CONTENT_BROWSER_EDITOR_CLIENT_OBSERVER_H_
+#define COMPONENTS_EDITING_CONTENT_BROWSER_EDITOR_CLIENT_OBSERVER_H_
+
+#include "content/public/browser/browser_message_filter.h"
+
+namespace content {
+class RenderViewHost;
+class WebContents;
+}
+
+namespace editing {
+
+class EditorClientObserver : public content::BrowserMessageFilter {
+ public:
+  EditorClientObserver(int render_process_id);
+
+  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+  virtual void OverrideThreadForMessage(const IPC::Message& message,
+                                        content::BrowserThread::ID* thread) OVERRIDE;
+ private:
+  void OnUndoNotify(int render_view_id, size_t undoStackSize);
+  void OnRedoNotify(int render_view_id, size_t redoStackSize);
+  void OnRegisterUndoNotify(int render_view_id, size_t undoStackSize);
+  void OnRegisterRedoNotify(int render_view_id, size_t redoStackSize);
+  void OnClearUndoStackNotify(int render_view_id, size_t undoStackSize);
+  void OnClearRedoStackNotify(int render_view_id, size_t redoStackSize);
+  int render_process_id_;
+};
+
+} // namespace editing
+
+#endif  // COMPONENTS_EDITING_CONTENT_BROWSER_EDITOR_CLIENT_OBSERVER_H_
diff --git a/tizen_src/impl/components/editing/content/common/editing_messages.h b/tizen_src/impl/components/editing/content/common/editing_messages.h
new file mode 100644 (file)
index 0000000..41af05c
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2013 Samsung Electronics. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ */
+
+// Multiply-included message file, hence no include guard.
+
+#include "content/public/common/common_param_traits.h"
+#include "content/public/common/common_param_traits_macros.h"
+#include "ipc/ipc_message_macros.h"
+#include "ipc/ipc_message_utils.h"
+
+#define IPC_MESSAGE_START EditingMsgStart
+
+// Editor messages sent from the renderer to the browser.
+
+// Notification message carrying undo stack size after executing undo
+IPC_MESSAGE_ROUTED2(EditingHostMsg_NotifyUndo,
+                    int, /* render view ID */
+                    size_t /* size of the undo stack */)
+
+// Notification message carrying redo stack size after executing redo
+IPC_MESSAGE_ROUTED2(EditingHostMsg_NotifyRedo,
+                    int, /* render view ID */
+                    size_t /* size of the redo stack */)
+
+// Notification message carrying undo stack size after registering undo
+IPC_MESSAGE_ROUTED2(EditingHostMsg_NotifyRegisterUndo,
+                    int, /* render view ID */
+                    size_t /* size of the undo stack */)
+
+// Notification message carrying redo stack size after registering redo
+IPC_MESSAGE_ROUTED2(EditingHostMsg_NotifyRegisterRedo,
+                    int, /* render view ID */
+                    size_t /* size of the redo stack */)
+
+// Notification message carrying undo stack size after clearing undo stack
+IPC_MESSAGE_ROUTED2(EditingHostMsg_NotifyClearUndo,
+                    int, /* render view ID */
+                    size_t /* size of the undo stack */)
+
+// Notification message carrying redo stack size after clearing redo stack
+IPC_MESSAGE_ROUTED2(EditingHostMsg_NotifyClearRedo,
+                    int, /* render view ID */
+                    size_t /* size of the redo stack */)
diff --git a/tizen_src/impl/components/editing/content/renderer/editorclient_agent.cc b/tizen_src/impl/components/editing/content/renderer/editorclient_agent.cc
new file mode 100644 (file)
index 0000000..af6051a
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2013 Samsung Electronics. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ */
+
+#include "components/editing/content/renderer/editorclient_agent.h"
+#include "third_party/WebKit/public/web/WebView.h"
+
+#include "content/public/renderer/render_view.h"
+#include "components/editing/content/common/editing_messages.h"
+
+using blink::WebEditorClient;
+using blink::WebString;
+
+namespace editing {
+
+EditorClientAgent::EditorClientAgent(content::RenderView* render_view)
+    : content::RenderViewObserver(render_view) {
+  render_view->GetWebView()->setEditorClient(this);
+}
+
+bool EditorClientAgent::OnMessageReceived(const IPC::Message& message) {
+  return false;
+}
+
+void EditorClientAgent::registerUndoStep(size_t undoStackSize) {
+  Send(new EditingHostMsg_NotifyRegisterUndo(routing_id(), routing_id(), undoStackSize));
+}
+
+void EditorClientAgent::registerRedoStep(size_t redoStackSize) {
+  Send(new EditingHostMsg_NotifyRegisterRedo(routing_id(), routing_id(), redoStackSize));
+}
+
+void EditorClientAgent::clearUndoRedoOperations(const std::string& command, size_t stackSize) {
+  if (command == "Undo")
+    Send(new EditingHostMsg_NotifyClearUndo(routing_id(), routing_id(), stackSize));
+  else if (command == "Redo")
+    Send(new EditingHostMsg_NotifyClearRedo(routing_id(), routing_id(), stackSize));
+}
+
+void EditorClientAgent::Undo(size_t undoStackSize) {
+  Send(new EditingHostMsg_NotifyUndo(routing_id(), routing_id(), undoStackSize));
+}
+
+void EditorClientAgent::Redo(size_t redoStackSize) {
+  Send(new EditingHostMsg_NotifyRedo(routing_id(), routing_id(), redoStackSize));
+}
+
+}  // namespace editing
diff --git a/tizen_src/impl/components/editing/content/renderer/editorclient_agent.h b/tizen_src/impl/components/editing/content/renderer/editorclient_agent.h
new file mode 100644 (file)
index 0000000..a1ab1fd
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2013 Samsung Electronics. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ */
+
+#ifndef COMPONENTS_EDITING_CONTENT_RENDERER_EDITORCLIENT_AGENT_H_
+#define COMPONENTS_EDITING_CONTENT_RENDERER_EDITORCLIENT_AGENT_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "content/public/renderer/render_view_observer.h"
+#include "third_party/WebKit/public/web/WebEditorClient.h"
+
+namespace editing {
+
+class EditorClientAgent : public content::RenderViewObserver,
+                          public blink::WebEditorClient {
+ public:
+  EditorClientAgent(content::RenderView* render_view);
+
+  // RenderView::Observer:
+  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ private:
+  // blink::WebEditorClient:
+  virtual void registerUndoStep(size_t undoStackSize);
+  virtual void registerRedoStep(size_t redoStackSize);
+  virtual void clearUndoRedoOperations(const std::string& command, size_t stackSize);
+  virtual void Undo(size_t undoStackSize);
+  virtual void Redo(size_t redoStackSize);
+};
+
+} // namespace editing
+
+#endif // COMPONENTS_EDITING_CONTENT_RENDERER_EDITORCLIENT_AGENT_H_